-
Notifications
You must be signed in to change notification settings - Fork 3
/
_shell_profile
462 lines (404 loc) · 9.6 KB
/
_shell_profile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
#####################################
# zetavg's shell profile 2020-01-16 #
#####################################
## Add `source "$HOME/.shell_profile"` to the main .profile ##
# CONSTANTS
export DEFAULT_NODEJS_VERSION=$(cat ~/.tool-versions | grep nodejs | awk -F' ' '{print $2}')
export DEFAULT_RUBY_VERSION=$(cat ~/.tool-versions | grep ruby | awk -F' ' '{print $2}')
export DEFAULT_ELIXIR_VERSION=$(cat ~/.tool-versions | grep elixir | awk -F' ' '{print $2}')
# PATH
PATH="$HOME/.bin:$PATH"
PATH="$HOME/.sbin:$PATH"
if [ -d "$HOME/Library/bin" ]; then
PATH="$HOME/Library/bin:$PATH"
fi
# ENV
if [[ $(uname) == "Darwin" ]]; then
export VISUAL='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -w'
fi
# CONFIG
# Let cd follow symbolic links
# (cd into `foo@ -> bar` will get into `bar`, not `foo`)
set -o physical
# ALIAS
alias repro='source $HOME/.shell_profile'
alias cls='cd;clear;test -e /etc/motd and cat /etc/motd;repro'
alias bye='exit'
alias l='ls -CF'
alias ll='ls -lFh'
if [[ `uname` == "Darwin" ]]; then
alias lll='CLICOLOR_FORCE=true ls -alFh -G | less -r'
else
alias lll='ls -alFh --color=always | less -r'
fi
alias la='ls -alFh'
alias lz='ls -lSrh'
alias lt='ls -ltrh'
alias lx='ls -lXBh'
alias up='cd ../'
alias cg="newgrp"
alias j='jobs'
alias startt='tmux new -s default'
alias tt='tmux attach -t default'
alias ns='screen -S'
alias rs='screen -r -x'
alias startscr='screen -S scr'
alias scr='screen -x scr'
alias nw='screen -X screen -t'
alias s='screen -X select'
alias roots='screen -X screen -t root 10 su'
alias sudosus='screen -X screen -t root 10 sudo su'
alias tops='screen -X screen -t top 9 top'
alias ptts='screen -X screen -t BBS 8 ssh [email protected]'
alias zshs='screen -X screen -t zsh zsh'
alias vis='screen -X screen -t vim vim'
alias gs='git status'
alias gss='git status --short --branch'
alias gsm='git status | more'
alias a='asdf'
alias R='rails'
alias RR='rails'
alias RN='react-native'
alias st='subl'
alias ss='subl'
alias gt='gittower'
alias trr='touch tmp/restart.txt'
alias ttr='touch tmp/restart.txt'
alias tdl='tail -f log/development.log'
alias geeknote='python $HOME/.bin/geeknote/geeknote.py'
alias gnsync='python $HOME/.bin/geeknote/gnsync.py'
alias pg8='ping 8.8.8.8'
alias ptt='ssh [email protected]'
# COMMANDS FOR COMPRESS AND DECOMPRESSING
# Usage:
# mk* OutputFileName.* InputDirName
# do* InputFileName
# un* InputFileName.*
#
# tar
alias mktar='tar cvf'
alias untar='tar xvf'
# gz
alias dogz='gzip'
alias ungz='gzip -d'
# tar.gz
alias mktar.gz='tar zcvf'
alias untar.gz='tar zxvf'
# bz
alias mkbz='echo "no mkbz"'
alias unbz='bzip2 -d'
# tar.bz
alias mktar.bz='echo "no mktar.bz"'
alias untar.bz='tar jxvf'
# bz2
alias dobz2='bzip2 -z'
alias unbz2='bzip2 -d'
# tar.bz2
alias mktar.bz2='tar jcvf'
alias untar.bz2='tar jxvf'
# tgz
alias mktgz='tar zcvf'
alias untgz='tar zxvf'
# tar.tgz
alias mktar.tgz='tar zcvf'
alias untar.tgz='tar zxvf'
# xz
alias mkxz='xz -z'
alias unxz='xz -d'
# tar.xz
alias mktar.xz='tar Jcvf'
alias untar.xz='tar Jxvf'
# Z
alias doZ='compress'
alias unZ='uncompress'
# tar.Z
alias mktar.Z='tar Zcvf'
alias untar.Z='tar Zxvf'
# 7z
alias mk7z='7z a'
alias un7z='7z x'
# rar
alias mkrar='rar'
alias unrar='rar e'
# lha
alias mklha='lha -a'
alias unlha='lha -e'
# FUNCTIONS
function mkcd() {
mkdir "$1"
cd "$1"
}
function bsd_color() {
local color_name=$1
case "$color_name" in
black)
echo 'a'
;;
red)
echo 'b'
;;
green)
echo 'c'
;;
yellow)
echo 'd'
;;
blue)
echo 'e'
;;
magenta)
echo 'f'
;;
cyan)
echo 'g'
;;
white)
echo 'h'
;;
bold_black)
echo 'A'
;;
bold_red)
echo 'B'
;;
bold_green)
echo 'C'
;;
bold_yellow)
echo 'D'
;;
bold_blue)
echo 'E'
;;
bold_magenta)
echo 'F'
;;
bold_cyan)
echo 'G'
;;
bold_white)
echo 'H'
;;
*)
echo 'x'
esac
}
function ansi_color() {
local color_name=$1
case "$color_name" in
bold)
echo '01'
;;
underline)
echo '04'
;;
black)
echo '30'
;;
red)
echo '31'
;;
green)
echo '32'
;;
yellow)
echo '33'
;;
blue)
echo '34'
;;
magenta)
echo '35'
;;
cyan)
echo '36'
;;
white)
echo '37'
;;
light_black)
echo '90'
;;
light_red)
echo '91'
;;
light_green)
echo '92'
;;
light_yellow)
echo '93'
;;
light_blue)
echo '94'
;;
light_magenta)
echo '95'
;;
light_cyan)
echo '96'
;;
light_white)
echo '97'
;;
black_bg)
echo '40'
;;
red_bg)
echo '41'
;;
green_bg)
echo '42'
;;
yellow_bg)
echo '43'
;;
blue_bg)
echo '44'
;;
magenta_bg)
echo '45'
;;
cyan_bg)
echo '46'
;;
white_bg)
echo '47'
;;
light_black_bg)
echo '100'
;;
light_red_bg)
echo '101'
;;
light_green_bg)
echo '102'
;;
light_yellow_bg)
echo '103'
;;
light_blue_bg)
echo '104'
;;
light_magenta_bg)
echo '105'
;;
light_cyan_bg)
echo '106'
;;
light_white_bg)
echo '107'
;;
*)
echo '00'
esac
}
# LS
function set_ls_color() {
local dir=cyan
local dir_bold=true
local dir_bg=
local sym_link=magenta
local sym_link_bold=true
local sym_link_bg=
local socket=green
local socket_bold=true
local socket_bg=
local pipe=yellow
local pipe_bold=true
local pipe_bg=
local exe=red
local exe_bold=true
local exe_bg=
local block_sp=blue
local block_sp_bold=false
local block_sp_bg=cyan
local char_sp=blue
local char_sp_bold=false
local char_sp_bg=yellow
local exe_suid=black
local exe_suid_bold=false
local exe_suid_bg=red
local exe_guid=black
local exe_guid_bold=false
local exe_guid_bg=cyan
local dir_sticky=black
local dir_sticky_bold=false
local dir_sticky_bg=green
local dir_wo_sticky=black
local dir_wo_sticky_bold=false
local dir_wo_sticky_bg=yellow
function _lscolor() {
local color=$1
local bold=$2
local bg_color=$3
local color_prefix
[[ "$bold" = 'true' ]] && color_prefix='bold_' || color_prefix=''
echo "$(bsd_color "${color_prefix}${color}")$(bsd_color "$bg_color")"
}
export LSCOLORS="$(_lscolor $dir $dir_bold $dir_bg)$(_lscolor $sym_link $sym_link_bold $sym_link_bg)$(_lscolor $socket $socket_bold $socket_bg)$(_lscolor $pipe $pipe_bold $pipe_bg)$(_lscolor $exe $exe_bold $exe_bg)$(_lscolor $block_sp $block_sp_bold $block_sp_bg)$(_lscolor $char_sp $char_sp_bold $char_sp_bg)$(_lscolor $exe_suid $exe_suid_bold $exe_suid_bg)$(_lscolor $exe_guid $exe_guid_bold $exe_guid_bg)$(_lscolor $dir_sticky $dir_sticky_bold $dir_sticky_bg)$(_lscolor $dir_wo_sticky $dir_wo_sticky_bold $dir_wo_sticky_bg)"
function _ls_color() {
local color=$1
local bold=$2
local bg_color=$3
local color_bold
[[ "$bold" = 'true' ]] && color_bold=";$(ansi_color 'bold')" || color_bold=''
local color_bg
[[ -z "$bg_color" ]] && color_bg='' || color_bg=";$(ansi_color "$bg_color")"
echo "$(ansi_color "$color")${color_bold}${color_bg}"
}
declare -x LS_COLORS="no=00:fi=00:di=$(_ls_color $dir $dir_bold $dir_bg):ln=$(_ls_color $sym_link $sym_link_bold $sym_link_bg):pi=$(_ls_color $pipe $pipe_bold $pipe_bg):so=$(_ls_color $socket $socket_bold $socket_bg):do=01;35:bd=$(_ls_color $block_sp $block_sp_bold $block_sp_bg):cd=$(_ls_color $char_sp $char_sp_bold $char_sp_bg):or=$(_ls_color $sym_link $sym_link_bold $sym_link_bg):ex=$(_ls_color $exe $exe_bold $exe_bg)"
}
set_ls_color
# NIXOS
# See https://nixos.org/nixos/manual/#sec-rollback
alias nixos-list-generations='ls -lt /nix/var/nix/profiles/system-*-link'
function nixos-switch-generation() {
local generation="$1"
generation="${generation//[!0-9]/}"
if [ -z "$generation" ]; then
>&2 echo "You need to specify a generation number as the argument."
return 1
fi
local generation_dir="/nix/var/nix/profiles/system-$generation-link"
if [ ! -d "$generation_dir" ]; then
>&2 echo "Generation $generation does not exists. Use nixos-list-generations to list all available generations."
return 1
fi
local generation_mod_time
generation_mod_time="$(stat -c %y "$generation_dir" | sed 's/\.[0-9]*//g')"
printf 'You are about to switch to generation %s (%s)' "$generation" "$generation_mod_time"
sleep 1; printf '.'; sleep 1; printf '.'; sleep 1; printf '.'
sleep 1; echo ''
local command="sudo $generation_dir/bin/switch-to-configuration switch"
printf 'Running "%s" in 3...' "$command"
sleep 1; printf ' 2...'; sleep 1; printf ' 1...'
sleep 1; echo ''
$command
}
# ASDF
# Only if the go executable is provided by asdf
if [[ "$(command -v go)" == *".asdf"* ]]; then
export GOPATH="$HOME/.go"
PATH="$PATH:$GOPATH/bin"
# TODO: run this every time after the go version has been switched
GOV=$(asdf current golang | sed 's/ (set by .*)//g')
export GOROOT="$HOME/.asdf/installs/golang/$GOV/go/"
fi
# ERLANG
# Persist erl/iex history
export ERL_AFLAGS="-kernel shell_history enabled"
# LOAD ENVIRONMENT SPECIFIC PROFILES
if [ -f "$HOME/.profile_other" ]; then
if [ -n "$FISH_VERSION" ]; then
bass source "$HOME/.profile_other"
else
source "$HOME/.profile_other"
fi
fi
if [ -f "$HOME/.profile_after_initialized" ]; then
if [ -n "$FISH_VERSION" ]; then
bass source "$HOME/.profile_after_initialized"
else
source "$HOME/.profile_after_initialized"
fi
fi