-
Notifications
You must be signed in to change notification settings - Fork 5
/
.alias
executable file
·367 lines (306 loc) · 8.85 KB
/
.alias
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
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC2086,SC2139,SC2142
# .bash_profile -> .alias
# Workaround
__vte_prompt_command() { true; }
# ew - Edit Which
# Quickly edit the source code of a command. This is pretty much a short
# cut for doing --> vim $(which mycommand)
ew(){
file_path=$(command -v "$1" 2>/dev/null)
if [ -z "$file_path" ]; then
printf "%s\n" "Error: $1 not found"
exit 1
fi
"$EDITOR" "$file_path"
}
export -f ew
git-wt(){
if [[ -z $1 ]]; then
selected=$(git worktree list --porcelain | awk -F'/' '/^worktree/ {print $NF}' | fzf)
else
selected="$1"
fi
cd "$(git worktree list | awk -v ws="$selected" '$NF == "["ws"]" {print $1}')"
}
export -f git-wt
load_session_manager_settings(){
### session managers
# check the window size after each command and, if necessary, update the values of LINES and COLUMNS.
shopt -s checkwinsize
# term settings
export TERM="${TERM:-screen-256color}"
export TMUX_TMPDIR="$HOME/.local"
alias ts="tmux-sessionizer"
}
load_editor_settings(){
### 'vim' settings
export EDITOR="vim"
if command -v nvim > /dev/null; then
export EDITOR="nvim"
alias vimdiff="nvim -d"
fi
export GIT_EDITOR="$EDITOR"
alias vim="$EDITOR"
alias vi="$EDITOR"
export PAGER="less"
export LESS="-FRSX"
}
load_python_settings(){
# Skip writing pyc and __pycache__
export PYTHONDONTWRITEBYTECODE=1
load_ansible_settings
}
load_ansible_settings(){
if command -v ansible &> /dev/null; then
export ANSIBLE_CALLBACK_WHITELIST="timer,profile_roles,profile_tasks,aws_resource_actions,counter_enabled"
export ANSIBLE_COMMAND_WARNINGS=0
export ANSIBLE_DEPRECATION_WARNINGS=0
export ANSIBLE_LOAD_CALLBACK_PLUGINS=1
export ANSIBLE_PIPELINING=1
export ANSIBLE_SSH_ARGS="-C -o ControlMaster=auto -o ControlPersist=60s"
export ANSIBLE_SYSTEM_WARNINGS=0
fi
}
load_node_settings(){
if ! command -v node &> /dev/null; then
return
fi
node_bin=$(dirname "$(readlink -f "$(command -v node)")")
add_to_path_if_exists "$node_bin"
}
load_golang_settings(){
unset GOROOT
# Go Settings
GOROOT="$(go env GOROOT 2>/dev/null)"
GOPATH="$HOME/gocode"
GOBIN="$GOPATH/bin"
# PATH Options. Reverse order of importance since they are prepended.
PATH_PARTS=(
"$GOBIN"
"$GOROOT/bin"
)
for path_part in "${PATH_PARTS[@]}"; do
add_to_path_if_exists "$path_part"
done
if command -v go &> /dev/null; then
export GOROOT
export GOPATH
export GOBIN
export GO111MODULE=on
fi
}
load_java_settings(){
local java_cmd java_bin java_path java_home
for java_cmd in java javac; do
# If there is no java program, try the next one
if ! command -v "$java_cmd" &> /dev/null; then
continue
fi
java_path=$(readlink -f "$(command -v "$java_cmd")")
if [[ -f "${java_path-}" ]]; then
# Transform /usr/local/jdk/bin/javac -> /usr/local/jdk/bin
java_bin=$(dirname "$java_path")
# Transform /usr/local/jdk/bin -> /usr/local/jdk
java_home=$(dirname "$java_bin")
if [[ -d "${java_bin-}" && -d "${java_home-}" ]]; then
add_to_path_if_exists "$java_bin"
JAVA_HOME="$java_home"; export JAVA_HOME
return # Stop after the first success
fi
fi
done
}
fix_path_ordering(){
local sorted_path
sorted_path=$(echo "${PATH}" |\
awk 'BEGIN { RS=":" } length > 1 { print length, $0 }' |\
sort -rn |\
cut -d' ' -f2 |\
paste -s -d: -)
PATH="${sorted_path}"; export PATH
}
add_to_path(){
local path_dir
path_dir="$1"
PATH="${path_dir}:${PATH}";
export PATH
fix_path_ordering
}
add_to_path_if_exists(){
local path_dir
path_dir="$1"
if [[ -d "$path_dir" ]]; then
if echo "${PATH}" | grep -vwq "${path_dir}"; then
add_to_path "$path_dir"
fi
fi
}
load_path_settings(){
# Always add these to PATH
PATH_PREPEND=(
"/usr/local/bin"
"/usr/local/opt/libpq/bin"
"/usr/local/opt/llvm/bin"
"$HOME/anaconda3/condabin"
"$HOME/anaconda3/bin"
"$HOME/bin"
"$HOME/.npm-packages/bin"
"$HOME/.cargo/bin"
"$HOME/.yarn/bin"
"$HOME/.local/bin"
"$HOME/.asdf/shims"
)
for path_part in "${PATH_PREPEND[@]}"; do
add_to_path_if_exists "$path_part"
done
# Shorten prompt
export PROMPT_DIRTRIM=3
# Load language settings
load_python_settings
load_golang_settings
load_node_settings
load_java_settings
}
load_alias_settings(){
### alias
alias ansible-lint="ansible-lint -c $HOME/.ansible-lint"
alias c="column -t -n -s ',' | less -S -R"
alias dstat-all='dstat -larm --top-io --top-latency'
alias ssh-keygen='ssh-keygen -t rsa -b 3072'
alias tb='command task pro:business'
alias tk='command task pro:tickler'
alias tp='command task pro:personal'
alias tt='command task $TASK_TAGS'
alias trv='command task pro:rv'
alias tw='command t waiting'
alias k9s='setterm --linewrap off; k9s'
alias terragrunt-clear-cache='find ./ -type d -name ".terragrunt-cache" -prune -exec rm -rf {} \;'
alias terragrunt-clear-debug='find ./ -type f -name "terragrunt-debug.tfvars.json" -prune -exec rm -rf {} \;'
if command -v rg > /dev/null; then
export FZF_DEFAULT_COMMAND="rg --files"
alias fgrep="rg -S"
else
alias fgrep="find . -type f | awk '!/CVS|\.class|\.jar|\.war|\.git|\.svn|_Stub|\.#/ {print \$0;}' | sed 's/\ /\\\ /g' | xargs grep --color=always -n "
fi
# Fix FZF completion for complex var exports
if [[ -f ~/.fzf/shell/completion.bash ]]; then
sed -i 's/export unset printenv/unset printenv/' ~/.fzf/shell/completion.bash
fi
## os-specific
if ls --color &> /dev/null; then
# We are on linux
alias ls='ls -lh --color'
else
# Mac OS settings
alias ls='ls -lh -G'
alias timeout='gtimeout'
fi
# clipboard copy/paste
if command -v xclip > /dev/null; then
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
fi
alias pgpsql='psql -U postgres'
# Autoenable direnv
command -v direnv &> /dev/null && eval "$(direnv hook bash)"
# Silence direnv output
export DIRENV_LOG_FORMAT=
unalias remake gmake make &> /dev/null
for make_prg in remake gmake make; do
if command -v "$make_prg" &> /dev/null; then
MAKE_PRG=$(command -v "$make_prg")
export MAKE_PRG
break
fi
done
alias make="$MAKE_PRG"
export MAKEFLAGS='-j8'
# Custom aliases
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias .......='cd ../../../../../..'
alias ........='cd ../../../../../../..'
alias -- -='cd -'
}
load_history_settings(){
### history
shopt -s histappend # append new history items to .bash_history
# We have bigly history. Some say the biggest history ever.
export HISTFILESIZE=10000000
export HISTSIZE="${HISTFILESIZE}"
export HISTFILE="$HOME/.bash_eternal_history"
export HISTCONTROL="ignoredups:erasedups:ignorespace"
if ! [[ "${PROMPT_COMMAND-}" =~ history ]]; then
PROMPT_COMMAND="history -a;history -n;${PROMPT_COMMAND-}"
export PROMPT_COMMAND
fi
}
load_lang_settings(){
# LANG
export LANG=en_us.UTF-8
export LC_ALL=en_US.UTF-8
export LC_COLLATE="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_MESSAGES="en_US.UTF-8"
export LC_MONETARY="en_US.UTF-8"
export LC_NUMERIC="en_US.UTF-8"
export LC_TIME="en_US.UTF-8"
export TZ='America/New_York'
}
load_extra_source_files(){
### source workstation-specific
SOURCEFILES=(
"$HOME/.local.alias"
"$HOME/.fzf.bash"
"$HOME/.local/share/bash-completion/*.bash"
"$HOME/anaconda3/etc/profile.d/*.sh"
"$HOME/.asdf/asdf.sh"
"$HOME/.asdf/completions/asdf.bash"
"/usr/local/etc/profile.d/autojump.sh"
"/usr/share/autojump/*.bash"
"/Applications/iTerm.app/Contents/Resources/iterm2_shell_integration.bash"
)
local sf glob_sf
# This actually works because
for sf in "${SOURCEFILES[@]}"; do
if compgen -G "$sf" &> /dev/null; then
for glob_sf in $(compgen -G "$sf"); do
source "$glob_sf"
done
fi
done
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
load_ps1_settings(){
# Check if PS1 is set (interactive shell)
if [[ -z ${PS1-} ]]; then
return
fi
PS1="\[\033[01;32m\]\u@\h \[\033[01;34m\]\w \[\033[33m\]\$(parse_git_branch)\[\033[00m\]$ "
}
load_shell_settings(){
unset MAILCHECK # Don't check mail when opening terminal.
# Get OS Arch ('linux' or 'darwin')
if [[ -z ${UNAME_S-} ]]; then
UNAME_S=$(uname -s | tr '[:upper:]' '[:lower:]')
export UNAME_S
fi
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export DOCKER_CONFIG="$HOME/.docker"
}
load_shell_settings
load_path_settings
load_session_manager_settings
load_editor_settings
load_history_settings
load_lang_settings
load_extra_source_files
load_ps1_settings
load_alias_settings
fix_path_ordering