/
dot-zshrc
356 lines (270 loc) · 9.06 KB
/
dot-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
353
354
355
356
# this zshrc is intended for linux use
#
# Because we don't want to commit our secrets to VCS, create
# a file named ".secrets" in your home directory and export all the secrets
# you have from there
#
################################################################################
LOG_START=`date +%s%N`
# vim 256 color support
export TERM=xterm-256color
### SHELL
## ZSH
source ~/.zinit/bin/zinit.zsh
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
zinit ice from"gh-r" as"program" atload'!eval $(starship init zsh)'
zinit light starship/starship
zinit for \
light-mode zdharma-continuum/history-search-multi-word
export NVM_LAZY_LOAD=true
zinit light lukechilds/zsh-nvm
zinit ice from"gh-r" as"program" mv"docker* -> docker-compose" bpick"*linux*"
zinit load docker/compose
zinit snippet OMZP::git
zinit snippet OMZL::history.zsh
# zinit snippet OMZP::tmux
zinit snippet OMZP::node
zinit snippet OMZP::docker-compose
zinit snippet OMZL::directories.zsh
zinit load djui/alias-tips
zinit load agkozak/zsh-z
zinit load wfxr/forgit
zinit wait lucid light-mode for \
atinit"zicompinit; zicdreplay" \
zdharma-continuum/fast-syntax-highlighting hlissner/zsh-autopair \
atload"_zsh_autosuggest_start" \
zsh-users/zsh-autosuggestions nnao45/zsh-kubectl-completion \
blockf atpull'zinit creinstall -q .' \
OMZL::completion.zsh zsh-users/zsh-completions\
# Up / Down arrow history search based on already typed command
bindkey "^[[A" history-beginning-search-backward
bindkey "^[[B" history-beginning-search-forward
# use Vi mode
bindkey -v
# make current line editable in vim
autoload edit-command-line; zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# autojump
alias j="autojump"
# grep coloring
alias grep="grep --color=auto"
# quicly source .zshrc
alias sz='source ~/.zshrc'
# Tools
# fuzzy finder for shell history
# https://github.com/junegunn/fzf
if [ -f $HOME/.fzf.zsh ]; then
source $HOME/.fzf.zsh
else
echo "install fzf into $HOME/.fzf.zsh"
echo "run 'git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install'"
echo
fi
if [ $commands[lsd] ]; then
alias ls='lsd'
alias lt='lsd --tree'
else
echo "install lsd https://github.com/Peltoche/lsd"
fi
# command line file manager
#
# install ranger
# > sudo pacman -S ranger
alias racd='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
alias ra='ranger'
# colorized cat
# http://pygments.org/docs/cmdline/
#
# install pygmentize
# > pacman -S pygmentize
alias c='pygmentize -O style=emacs -f console256 -g'
alias urlencode='python -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1] if len(sys.argv) > 1 else sys.stdin.read()[0:-1]))"'
alias urldecode='python -c "import urllib.parse, sys; print(urllib.parse.unquote(sys.argv[1] if len(sys.argv) > 1 else sys.stdin.read()[0:-1]))"'
# functions
function killport() {
fuser -k $1/tcp
}
# ssh
## check if ssh agent is already running by looking for keys to be added
ssh-add -l &>/dev/null
if [ "$?" = 2 ]; then
# if not ssh-agent is running, try to load from file
test -r ~/.ssh-agent && \
eval "$(<~/.ssh-agent)" >/dev/null
# if there is no ~/.ssh-agent, start the ssh agent and save it to file
ssh-add -l &>/dev/null
if [ "$?" = 2 ]; then
(umask 066; ssh-agent > ~/.ssh-agent)
eval "$(<~/.ssh-agent)" >/dev/null
ssh-add
fi
fi
# editor
export EDITOR="nvim"
if [ -d /snap/bin/ ]
then
PATH=$PATH:/snap/bin
fi
# # tmuxinator
# Install ruby for tmuxinator
# > sudo pacman -S Ruby
#
# then install tmuxinator
# > gem install tmuxinator
#
# RUBY_VERSION=$(gem environment | grep PATHS -A 2 | grep home | grep -Eo '[0-9]+.[0-9]+.[0-9]+' | head -n 1)
# export PATH="$PATH:/home/nazgul/.gem/ruby/$RUBY_VERSION/bin"
# install autocomplete for tmuxinator
# > sudo wget -P /usr/bin/ https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.zsh
# > sudo chmod +x /usr/bin/tmuxinator.zsh
### DEVELOPMENT
## ASDF
#
. $HOME/.asdf/asdf.sh
# append completions to fpath
fpath=(${ASDF_DIR}/completions $fpath)
# initialise completions with ZSH's compinit
autoload -Uz compinit && compinit
## NODE.JS
# overwrite builtin directory movements to use nvm
function cd () {
builtin cd "$@" && nvm use 2>/dev/null
}
function popd () {
builtin popd "$@" && nvm use 2>/dev/null
}
function pushd () {
builtin pushd "$@" && nvm use 2>/dev/null
}
# NPM
alias npml="npm run lint -- --fix 2> /dev/null"
alias npmt="npm t 2> /dev/null"
alias npmlt="npml && npmt"
## DENO
export DENO_INSTALL="/home/nazgul/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
## Elixir
export PATH=~/.mix/escripts:$PATH
## GO
export PATH=$PATH:/usr/local/go/bin
## PHP
# Composer
#
# go to https://getcomposer.org/download/ to install composer,
# then move composer.phar to /usr/local/bin/composer/
function composer() {
php /usr/local/bin/composer/composer.phar $@
}
## Rust
export PATH=$PATH:$HOME/.cargo/bin
## Ruby
if [ -f $HOME/.rvm/scripts/rvm ]; then
source /home/nazgul/.rvm/scripts/rvm
fi
export PATH="$HOME/.rbenv/bin:$PATH"
if hash -v rbenv > /dev/null; then
eval "$(rbenv init -)"
fi
### DEVOPS
## Generic
export PATH=~/.local/bin:$PATH
## Fly.io
export FLYCTL_INSTALL="$HOME/.fly"
export PATH="$FLYCTL_INSTALL/bin:$PATH"
## KUBERNETES
# The next line updates PATH for the Google Cloud SDK.
# if [ -f "$HOME/google-cloud-sdk/path.zsh.inc" ]; then . "$HOME/google-cloud-sdk/path.zsh.inc"; fi
alias kc='kubectl'
## Docker
alias up='docker-compose up'
alias down='docker-compose down'
### HOME APPLICATIONS
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
alias isod='date +%Y-%m-%d'
alias xo='xdg-open'
export XDG_DATA_DIRS="$XDG_DATA_DIRS:/var/lib/flatpak/exports/share/applications"
function clock() {
while true
do
echo -n `date "+%A %Y-%m-%d %H:%M:%S"`
sleep 1
echo -en "\r"
done
}
countdown() (
if [ -z $1 ]; then
echo "Usage:"
echo "countdown \"00:00:10\" # 10 sec"
echo "countdown \"00:00:30\" # 30 sec"
echo "countdown \"00:01:42\" # 1 min 42 sec"
exit 1
fi
hours=$(awk -F ":" '{ print $1 }' <<< $1)
minutes=$(awk -F ":" '{ print $2 }' <<< $1)
seconds=$(awk -F ":" '{ print $3 }' <<< $1)
secs=$(( $hours * 3600 + $minutes * 60 + $seconds ))
while [ $secs -gt 0 ]
do
sleep 1 &
printf "\r%02d:%02d:%02d" $((secs/3600)) $(( (secs/60)%60)) $((secs%60))
secs=$(( $secs - 1 ))
wait
done
echo
)
## Navigation
# Jump to dotfiles
# jump instantly to applications directory
hash -d -- apps='/usr/share/applications/'
hash -d -- dot="$HOME/Projects/src/github.com/Shadowbeetle/dotfiles/"
alias cdot='code ~/Projects/src/github.com/Shadowbeetle/dotfiles'
alias vdot="$EDITOR ~/Projects/src/github.com/Shadowbeetle/dotfiles"
alias vv="$EDITOR ~/.vimrc"
alias vn="$EDITOR ~/.config/nvim/init.vim"
alias vz="$EDITOR ~/.zshrc"
hash -d -- notes="$HOME/Dropbox/Notes/"
alias cnotes='code ~/Dropbox/Notes'
alias vnotes="$EDITOR ~/Dropbox/Notes"
LOG_END=`date +%s%N`
# if [ $commands[neofetch] ]; then
# neofetch
# else
# echo "install neofetch to get a nice welcome"
# fi
echo Startup took $((($LOG_END - $LOG_START) / (1000 * 1000))) milliseconds
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh
# heroku autocomplete setup
# HEROKU_AC_ZSH_SETUP_PATH=/home/nazgul/.cache/heroku/autocomplete/zsh_setup && test -f $HEROKU_AC_ZSH_SETUP_PATH && source $HEROKU_AC_ZSH_SETUP_PATH; # SLOW
### Added by Zinit's installer
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
print -P "%F{33}▓▒░ %F{220}Installing %F{33}DHARMA%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$HOME/.zinit" && command chmod g-rwX "$HOME/.zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.zinit/bin" && \
print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \
print -P "%F{160}▓▒░ The clone has failed.%f%b"
fi
source "$HOME/.zinit/bin/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
### End of Zinit's installer chunk
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
zdharma-continuum/zinit-annex-as-monitor \
zdharma-continuum/zinit-annex-bin-gem-node \
zdharma-continuum/zinit-annex-patch-dl \
zdharma-continuum/zinit-annex-rust
### End of Zinit's installer chunk
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/home/nazgul/google-cloud-sdk/path.zsh.inc' ]; then . '/home/nazgul/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/home/nazgul/google-cloud-sdk/completion.zsh.inc' ]; then . '/home/nazgul/google-cloud-sdk/completion.zsh.inc'; fi