-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zsh.aliases
299 lines (253 loc) · 9.37 KB
/
.zsh.aliases
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
#PROMPT='[%*] [%{$fg[cyan]%}${PWD/#$HOME/~}%{$reset_color%}]${ret_status}%m> %{$reset_color%}'
zmodload zsh/system
autoload colors && colors
autoload -Uz vcs_info
autoload bashcompinit
# Disable all vcs I don't use, enable only the one I do
zstyle ':vcs_info:*' enable NONE
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr '%F{yellow}✗ '
zstyle ':vcs_info:git*' formats "%F{62}%s:(%F{9}%b%F{62}) %u%{$reset_color%}%m%{$reset_color%}"
precmd() { vcs_info }
setopt PROMPT_SUBST
PROMPT='${vcs_info_msg_0_}[%*] [%F{cyan}%~%f] %(?.%F{green}.%F{9})%m%f%(!.#.>) '
# Load zsh/system so I can use zsh's builtin flock
zmodload -aF zsh/system
# Because some fool somewhere is doing 'bindkey -v'
bindkey -e
export PATH=${PATH}:${HOME}/bin:${HOME}/.local/bin:/usr/local/sbin:${HOME}/pip/bin:/usr/local/opt/mysql-client/bin
# Uncomment this to get more timing details about the progress of sourcing in this file
#export _SILENCE_TMSG=0
#echo " Sourcing in .zsh/ files .. "
# This is defined as msgStatus() in dependency_vars.sh, but since we are want to use it before we source that
# in, we do this manually this one time.
#tput sc
#tput el
#echo -n " sourcing .zsh/dependency_vars.sh"
#tput rc
source ${HOME}/.zsh/dependency_vars.sh
#msgStatus " .zsh/dependency_vars.sh sourcing complete"
source_dot_d_files "${HOME}/.zsh/local.d"
#msg ""
#tmsg "continuing with .zsh.aliases"
export PATH=${PATH}:${HOME}/bin:/usr/local/sbin:${HOME}/repos/nightly/utility_scripts/users/dylan/mariadb:${HOME}/repos/nightly/utility_scripts/users/dylan/maxscale:${HOME}/repos/nightly/utility_scripts/users/dylan/kubernetes:${HOME}/pip/bin:/usr/local/opt/mysql-client/bin
export GREP_COLORS='ms=01;33:mc=01;33:sl=:cx=:fn=35;107:ln=32:bn=32:se=35;47'
# zsh behavior modifications
bindkey \^U backward-kill-line
# Rust path addition and tool aliases
export PATH=${PATH}:${HOME}/.cargo/bin
# rbenv
tmsg "Doing eval for rbenv"
eval "$(rbenv init - zsh)"
PATH=${PATH}:${HOME}/.gem/ruby/$(realcat ${HOME}/.rbenv/version)/bin
alias rbupdate="git -C $(rbenv root)/plugins/ruby-build pull"
# Python BS
export PATH=${PATH}:${HOME}/.local/bin
escurl() {
curl -sSL "${ES_URL}${1}"
}
espost() {
curl -sSL -XPOST "${ES_URL}${1}"
}
esput() {
endpoint="$1"; shift
curl -sSL -XPUT -H 'Content-type: application/json' "${ES_URL}${endpoint}" "$@"
}
danger_delete_index() {
if [[ ! -z "${1}" ]]; then
2>&1 echo "Sending delete to ${ES_URL} for index ${1}"
curl -X DELETE "${ES_URL}/${1}"
fi
}
function quiet_on_success() {
set +e
output="$($*)"
retval=$?
set -e
if [[ $retval -gt 0 ]]; then
echo "${output}"
exit $retval
fi
}
tmsg "Setting up aliases"
# User specific aliases and functions
alias cls='clear; ls'
alias cll='clear; ll'
alias curl='curl -sSL'
alias curlv='curl -sSL -o /dev/null -v'
alias curlvt='curl -sSL -o /dev/null -v -w "HTTP Code: %{response_code}; Connect time: %{time_connect}; Total time:%{time_total}\n"'
alias curlhead='curl -sSL -D - -o /dev/null'
alias fl8='flake8-3 --ignore=E111,E114,E129'
alias gla="git la"
alias localdb='mysql -h 127.0.0.1 -P 3306 -u root'
alias more='\less -REX'
alias prespace='sed -e "s/^/ /g"'
alias random='echo $(( ( RANDOM % 60 ) + 1 ))'
alias repos='ls ~/repos'
alias rf='resetfile'
alias s3cmd="$HOME/bin/gs3"
alias ta='tmux -u new -t 0'
alias view='nvim -R'
alias vi='nvim'
alias vim='nvim'
alias vimdiff='nvim -d'
# Set up directory history
export DIRSTACKSIZE=10
setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups
alias dh='dirs -v'
# Environment variables
tmsg "Setting ENV variables"
export EDITOR='vim'
export LSCOLORS=hxgxcxdxCxegedabagacad
export LESS='-REX'
setopt extended_glob
unsetopt beep
setopt prompt_bang
export CACHE_AGE=6000
function vd() {
vimdiff ~/${1} ~/dotfiles/${1}
}
function ckssh() {
ssh-keygen -f "$HOME/.ssh/known_hosts" -R $*
ssh $*
}
## tmux stuff
tmsg "Setting up tmux functions/aliases"
function ta {
tmux has-session -t 0
if [ $? != 0 ]; then
tmux new-session -s 0 -n "$(~/bin/random_line.rb ~/.tmux/window_names)"
fi
tmux attach -t 0
}
function checkForStaleTmuxSessions() {
! /usr/bin/pgrep tmux > /dev/null && return
local _staleTmuxPanes=$(tmux list-panes | wc -l | awk '{print $1}')
local _staleTmuxSessions=$(tmux list-sessions | grep -v 'attached' | wc -l | awk '{print $1}')
if [[ ${_staleTmuxPanes:-0} -gt 1000 && ${_staleTmuxSessions:-0} -gt 10 ]]; then
echo "The number of tmux panes and stale sessions is above our thresholds."
echo "Proceeding to kill off some sessions to clean up stale items"
for i in $(tmux list-sessions | awk -F: '!/attached/ {print $1}'); do
echo "Killing tmux session '${i}"
tmux kill-session -t ${i}
sleep 1
done
fi
}
checkForStaleTmuxSessions
tmsg "Setting TMUX_PANE value"
if [ ! -z "${TMUX_PANE}" ]; then
export PANE_NUM=$(tmux list-panes -a | grep $TMUX_PANE 2>/dev/null | awk -F: '{print $2}' | awk -F. '{print $2}' | uniq)
fi
tmsg "Defining regen_pane_num()"
regen_pane_num() {
export PANE_NUM=$(tmux list-panes -a | grep $TMUX_PANE 2>/dev/null | awk -F: '{print $2}' | awk -F. '{print $2}' | uniq)
}
### Functions
tmsg "adding some functions [line 169]"
alias functions="typeset -f | rg --color=never '^[a-z]+ \\(\\)' | sed -e 's/ *() *{//' | sort"
emw() {
mwin $(echo $*)
}
ctdir() {
PANE=$(echo "${TMUX_PANE}" | sed -e 's/^%//')
DIRS=$(find -maxdepth 1 -type d | grep -v '^.$' | \grep -E "./$*")
DIR_NUM=$(echo "${DIRS}" | wc -l)
TARGET=$(( ${PANE} % ${DIR_NUM} + 1 ))
cd $(echo "${DIRS}" | head -${TARGET} | tail -1)
}
addsshkey() {
ssh-copy-id -i ~/.ssh/id_rsa.pub $*
ssh $*
}
distsshkey() {
ssh -o PreferredAuthentications=publickey -o KbdInteractiveAuthentication=no -o PasswordAuthentication=no -o StrictHostKeyChecking=no $* 'hostname'
if [ $? == 255 ]; then
ssh-copy-id -i ~/.ssh/id_rsa.pub $*
else
echo "Was able to log in. No need to copy id"
fi
}
distkey() {
distsshkey $*
}
delhostkey() {
ssh-keygen -f ~/.ssh/known_hosts -R "$*"
}
cab() {
curlv http://${1}${3} | hlhttp
curlv http://${2}${3} | hlhttp
}
# GPG helper functions
tmsg "Defining gpg helper functions"
encrypt() {
if [ -f "${@}.gpg" ]; then
rm ${@}.gpg
fi
gpg --encrypt --recipient '[email protected]' $@
rm $@
}
decrypt() {
FNAME=$(echo $@ | sed -e 's/.gpg$//')
gpg --output $FNAME --decrypt $@
}
decat() {
gpg --decrypt $@
}
notes() {
NDIR="~/tickets/$@"
mkdir $NDIR
cd $NDIR
vim notes
}
tmsg "Setting zstyle completion [285]"
zstyle :completion::::: completer _complete _files
tmsg "Defining _shellExit() [288]"
function _shellExit() {
echo "## Running _shellExit()"
_histFile="${HISTFILE:-${HOME}/.zsh_history}"
if [[ ! -e "${_histFile}" ]]; then
echo " No histfile found. Exiting."
exit
fi
zsystem supports flock || \
echo " No zsystem command found that supports flock. Exiting." && \
exit
echo " Looping until I can get a lock on the history file"
while true; do
echo " _histFile is '${_histFile}'"
spinner
# Timeout after 5 seconds.
if zsystem flock -t 5 -f histlock ${_histFile}; then
echo " Got zlock for ${_histFile}. Saving history."
fc -A
break
fi
sleep 0.1
done
echo " History saved. Exiting."
echo ""
}
tmsg "Trapping _shellExit() [294]"
trap _shellExit EXIT
tmsg "Done with .zsh.aliases [296]"
# User-Agent Strings
# These are some example UA strings for use in curl strings
# Don't really need these nearly as much, so commenting them out, but leaving if I ever
# care to uncomment for a specific purpose
##export AMIGA='AmigaVoyager/2.95 (compatible; MC680x0; AmigaOS)'
##export AND4='Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
##export AND23='Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
##export BB='Mozilla/5.0 (BlackBerry; U; BlackBerry 9860; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.254 Mobile Safari/534.11+'
##export CHROME='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17'
##export FIREFOX='Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1'
##export IEMOBILE='Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)'
##export IPHONE='Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5'
##export IPAD='Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'
##export SAFARI='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2'
##export SAMSUNGU365='SCH-U365/1.0.NetFront/3.0.22.2.23.(GUI).MMP/2.0'
##export WP7='Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)'
##export WP8='Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920'
##export BB9700='BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/120'
##export NOKIA8310='Mozilla/5.0 (Symbian/3; Series60/5.3 NokiaE7-00/111.040.1511; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/535.1 (KHTML, like Gecko) NokiaBrowser/8.3.1.4 Mobile Safari/535.1'