-
Notifications
You must be signed in to change notification settings - Fork 2
/
.zshrc
352 lines (290 loc) · 8.92 KB
/
.zshrc
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
#export TERM=screen-256color
export TERM=xterm-256color
echo 🦈
# Load Antigen
source ~/antigen.zsh
# Load Antigen configurations
antigen init ~/.antigenrc
echo 🐋
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin:/usr/local/go/bin:/usr/local/kubebuilder/bin
export PATH=$PATH:~/.local/lib/python2.7/site-packages
export PATH=$PATH:~/.local/lib/python3.5/site-packages
export PATH=$PATH:~/.local/lib/python3.6/site-packages
export PATH=$PATH:~/.local/bin
export PATH=$PATH:/snap/bin
export PATH=$PATH:/home/ben/bin
export PATH=$PATH:$HOME/.dotnet/tools
export DOTNET_ROOT=$HOME/.dotnet
export DOTNET_HOME=$HOME/.dotnet
export PATH=$PATH:$DOTNET_ROOT
# The following lines were added by compinstall
zstyle ':completion:*' completer _expand _complete _ignored _approximate
zstyle :compinstall filename '/home/ben/.zshrc'
autoload -Uz compinit
compinit
autoload bashcompinit
bashcompinit
source /etc/bash_completion.d/azure-cli
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=1000
setopt autocd extendedglob
bindkey -v
# End of lines configured by zsh-newuser-install
### --------------- Custom ------------------
# autoload -U colors && colors
# autoload -U promptinit && promptinit
# Reset command output to normal font
preexec() { printf "\e[0m"; }
# Spellcheck suggestions for mis-typed commands
setopt correct
function insert-mode () { echo "%F{blue}⇉ ⇉ ⇉" }
function normal-mode () { echo "%F{green}↘ ↘ ↘" }
function set-prompt () {
LAST_EXIT_CODE=$?
ERR=""
# ignore 0, ctrl-c
if [[ $LAST_EXIT_CODE -ne 0 && $LAST_EXIT_CODE -ne 130 ]]; then
ERR="$LAST_EXIT_CODE "
fi
case ${KEYMAP} in
(vicmd) VI_MODE="$(normal-mode)" ;;
(main|viins) VI_MODE="$(insert-mode)" ;;
(*) VI_MODE="$(insert-mode)" ;;
esac
# Space is a non-breaking space to support reverse prompt navigation with tmux search
PS1="$ERR$VI_MODE %F{yellow}"
}
function zle-line-init zle-keymap-select {
set-prompt
zle reset-prompt
}
# preexec () { print -rn -- $terminfo[el]; }
zle -N zle-line-init
zle -N zle-keymap-select
# export KEYTIMEOUT=3
function reloadrc() {
source ~/.zshrc
}
zle -N reloadrc
#function adv_history() {
# BUFFER="$(atuin history list --cmd-only | fzf-tmux)"
# zle end-of-line
#}
#zle -N adv_history
bindkey -M viins 'jk' vi-cmd-mode
bindkey -M viins ',d' reloadrc
# Set search_mode to "fuzzy" in ~/.config/atuin/config.toml
bindkey ',r' _atuin_search_widget
#bindkey ',r' adv_history
#bindkey -M viins ',r' history-incremental-pattern-search-backward
bindkey -M viins '^r' zaw-history
bindkey -M vicmd '^r' zaw-history
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
fzf-complete-from-tmux() {
BUFFER+="$( \
tmux capture-pane -pS -100000 | \
tac | \
pcregrep -o "[\w\d_\-\.\/]+" | \
awk '{ if (!seen[$0]++) print }' | \
fzf-tmux --no-sort --exact \
)"
zle end-of-line
}
zle -N fzf-complete-from-tmux
bindkey -M viins ',c' fzf-complete-from-tmux
bindkey -M vicmd ',c' fzf-complete-from-tmux
bindkey -M viins ',z' zaw-git-recent-branches
bindkey -M viins ',s' zaw-git-log
bindkey -M viins ',a' zaw-ack
bindkey -M viins ',t' zaw-tmux
eval "$(lua ~/z.lua --init zsh echo)"
# z.lua with fzf interactive
alias f="z -I | fzf-tmux"
alias vim="nvim"
alias vi="nvim"
# Override annoying expansions from zsh globalalias plugin
unalias -m "grep"
alias freeram="sudo sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches"
alias p=python3
alias pip=pip3
alias pip2=/usr/bin/pip
function run-with-less() {
BUFFER+=" | less"
zle accept-line
}
function run-with-rg() {
BUFFER+=" | rg -i "
zle end-of-line
}
function run-with-watch() {
BUFFER="watch -n 2 '$BUFFER'"
zle end-of-line
}
function run-with-xargs() {
BUFFER+=" | xargs -I % bash -c '"
zle end-of-line
}
zle -N run-with-less
zle -N run-with-rg
zle -N run-with-watch
zle -N run-with-xargs
bindkey -M viins ',l' run-with-less
bindkey -M vicmd ',l' run-with-less
bindkey -M viins ',g' run-with-rg
bindkey -M vicmd ',g' run-with-rg
bindkey -M viins ',w' run-with-watch
bindkey -M vicmd ',w' run-with-watch
bindkey -M viins ',v' edit-command-line
bindkey -M vicmd ',v' edit-command-line
bindkey -M viins ',x' run-with-xargs
bindkey -M vicmd ',x' run-with-xargs
. ~/zshrc.msft
function r() {
rg -i $@
}
function ry() {
rg -i $@ -g '*.yaml' -g '*.yml'
}
function rf() {
rg -i "${@:2}" -g "*.$1"
}
function rgo() {
rg -i $@ -g '!vendor*' -g '*.go'
}
alias gi="ginkgo"
alias gif="ginkgo --focus="
alias fz="fzf-tmux"
# quick aliasing for repetitive, but throwaway, tasks
function a() {
alias $1="${*:2}"
echo "Set up alias $1=\"${*:2}\""
}
alias rmswap="rm ~/.local/share/nvim/swap/*"
alias pwshrc="nvim ~/.config/powershell/Microsoft.PowerShell_profile.ps1"
alias zshrc="nvim ~/.zshrc"
alias -s yaml=vim
alias -s go=vim
# Enable aliases with watch
alias watch="watch "
alias gs="git status"
alias ga="git add"
alias gap="git add -p"
alias gau="git add -u"
alias gm="git commit -m "
alias gam="git add -u; git commit -m"
alias grr="git add -u; git commit --amend --no-edit"
alias gd="git diff --color"
alias gdc="git diff --color -U0"
alias gco="git checkout"
alias gcob="git checkout -b benbp/"
alias gl="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit -n10"
alias glg="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit"
alias gpo="git push origin"
alias gpu='git push -u origin $(git rev-parse --abbrev-ref HEAD)'
alias gpf='git push -u fork $(git rev-parse --abbrev-ref HEAD)'
alias gpa='git push -u fork $(git rev-parse --abbrev-ref HEAD); git push -u origin $(git rev-parse --abbrev-ref HEAD)'
alias gpl="git fetch --all --prune; git pull --rebase"
alias gf="git fetch --all --prune"
alias gre="git remote"
alias grei="git rebase -i"
alias grb2="git rebase -i HEAD~2"
alias grb3="git rebase -i HEAD~3"
alias grb5="git rebase -i HEAD~5"
alias grbt="git rebase -i HEAD~10"
alias grb="git rebase -i HEAD~5"
alias grbc="git rebase --continue"
alias grba="git rebase --abort"
alias grbe='vim $(git diff --name-only | uniq)'
alias gba="git branch -a"
alias gcp="git cherry-pick"
alias gst="git stash"
alias gstp="git stash pop"
alias ggrep="git grep -i --color --break --heading --line-number"
alias rebase="git fetch --all --prune; git rebase origin/main"
alias gn="git fetch --all; git checkout origin/main; git checkout -b benbp/"
alias gui="git update-index --assume-unchanged"
alias guin="git update-index --no-assume-unchanged"
function groot() {
cd $(git rev-parse --show-toplevel)
}
function gpa() {
gh pr review --approve $1
}
function update_gh() {
pushd ~
VERSION=$1
echo "VERSION SHOULD NOT BE EMPTY: '$VERSION'. Run update_gh <version>"
wget https://github.com/cli/cli/releases/download/v${VERSION}/gh_${VERSION}_linux_amd64.deb
sudo dpkg -i gh_${VERSION}_linux_amd64.deb
rm gh_${VERSION}_linux_amd64.deb
gh version
popd
}
# ----- Az -----
alias sub="az fzf subscription"
alias group="az fzf group -d"
# ----- Kubectl -----
function kc() {
export KUBECONFIG="$1"
}
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
alias k=kubectl
alias h=helm
source <(k completion zsh)
# Logs
alias kl='k logs'
alias klf='k logs -f'
# Namespace management
alias kgns='k get namespaces'
alias kcn='k config set-context $(k config current-context) --namespace'
alias kcu='k config use-context'
# Pod management
alias kgp='k get pods'
alias kgpa='k get pods -A | rg -v kube-system'
alias kgpw='kgp --watch'
alias kgpwide='kgp -o wide'
alias kep='k edit pods'
alias kdp='k describe pods'
# Resource management
alias kgn='k get nodes'
alias ktn='k top nodes'
alias ktp='k top pods'
alias ktpa='k top pods -A'
# Apply a YML file
alias kaf='k apply -f'
# Drop into an interactive terminal on a container
alias keti='k exec -ti'
function x() {
cat - | xargs -I % bash -c "$@"
}
function y() {
echo $@
}
function col() {
cmd='{print $'$1}
cat - | awk $cmd
}
function load-git-keys() {
eval `ssh-agent` > /dev/null 2>&1
#ssh-add ~/.ssh/id_rsa.vsts > /dev/null 2>&1
#ssh-add ~/.ssh/id_rsa.github.2 > /dev/null 2>&1
ssh-add ~/.ssh/id_rsa.github > /dev/null 2>&1
}
# alias refreshdate="sudo ntpdate us.pool.ntp.org"
# alias refreshdate="echo 'sudo hwclock -s'; sudo hwclock -s"
alias refreshdate="echo 'sudo ntpdate time.windows.com'; sudo ntpdate time.windows.com"
load-git-keys
alias tmux='tmux -2'
if [ "$TMUX" = "" ]; then
tmux attach-session -t wsl_tmux || tmux new-session -s wsl_tmux;
fi
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# https://github.com/ellie/atuin
export ATUIN_NOBIND="true"
eval "$(atuin init zsh)"