-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot_zshrc
362 lines (295 loc) · 10.6 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
357
358
359
360
361
362
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH"
export ZSH=$HOME/.oh-my-zsh
source $ZSH/oh-my-zsh.sh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="agnoster"
if [ "$(uname)" = "Darwin" ]; then
export ANDROID_HOME=$HOME/Library/Android/Sdk
elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
export ANDROID_HOME=$HOME/Android/Sdk
export CHROME_EXECUTABLE=google-chrome-stable
alias google-chrome='google-chrome-stable'
fi
plugins=(git zshmarks)
eval "$(starship init `basename $SHELL`)"
alias vi=nvim
alias vim=nvim
[ -s "$HOME/.jabba/jabba.sh" ] && source "$HOME/.jabba/jabba.sh"
export PATH="$PATH:$HOME/flutter/bin"
export PATH="$PATH":"$HOME/flutter/.pub-cache/bin"
export REDIS_URL="redis://localhost:6379"
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# The next line updates PATH for the Google Cloud SDK.
if [ -f '$HOME/tmp/google-cloud-sdk/path.zsh.inc' ]; then . '$HOME/tmp/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '$HOME/tmp/google-cloud-sdk/completion.zsh.inc' ]; then . '$HOME/tmp/google-cloud-sdk/completion.zsh.inc'; fi
export FLYCTL_INSTALL="$HOME/.fly"
export PATH="$FLYCTL_INSTALL/bin:$PATH"
export DENO_INSTALL="/home/kodingwarrior/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
export RUST_BACKTRACE="full"
export PATH="$PATH":"$HOME/.pub-cache/bin"
export PATH="$PATH":"/usr/share/idea/bin"
if [ "$(uname)" = "Darwin" ]; then
source ~/credentials.sh
elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then
source ~/credentials.sh
fi
export PATH="$PATH":"$HOME/.maestro/bin"
export PATH="$HOME/go/bin:${PATH}"
export PATH="$HOME/.local/share/mise/shims:${PATH}"
######
# Alias commands
######
if command -v lsd &>/dev/null; then
# Bypass this problem
#
# lsd: aliased to command ls -d *(/)
alias ls='lsd'
alias _lsd="mise x lsd -- lsd"
alias l="_lsd -Ah"
alias la="_lsd -Ah"
alias ll="_lsd -Alh"
alias lla="_lsd -lAh"
alias lt="_l -Ah --tree"
elif command -v exa &>/dev/null; then
alias l="exa -s type"
alias la="exa -s type -a"
alias ll="exa -s type -l"
alias llg="exa -s type -l --git"
alias lla="exa -s type -la"
alias lt="exa -s type --tree -l"
else
alias l="ls -Ah"
alias la="ls -Ah"
alias ll="ls -lAh"
alias lla="ls -lAh"
fi
if command -v rg &>/dev/null; then
alias rg="rg --hidden --smart-case --context=3"
fi
if command -v zoxide &>/dev/null; then
eval "$(zoxide init zsh)"
alias zx="zoxide"
function zii() {
__zoxide_zi "$@"
}
fi
alias mr='mise run'
################################
# Zinit
################################
zinit_home="${HOME}/.local/zsh/zinit"
declare -A ZINIT
ZINIT[HOME_DIR]="${zinit_home}"
ZINIT[BIN_DIR]="${zinit_home}/bin"
ZINIT[ZMODULES_DIR]="${zinit_home}/zmodules"
ZINIT[ZCOMPDUMP_PATH]="${HOME}/.local/zcompdump"
if [[ -s "${zinit_home}/bin/zinit.zsh" ]]
then
source "${zinit_home}/bin/zinit.zsh"
if [[ "$_ZSH_INIT_MINIMAL" != true ]]; then
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
fi
# https://github.com/ohmyzsh/ohmyzsh/blob/master/lib
zinit snippet OMZ::lib/clipboard.zsh
zinit snippet OMZ::lib/completion.zsh
zinit snippet OMZ::lib/history.zsh
zinit snippet OMZ::lib/key-bindings.zsh
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-syntax-highlighting
# zinit snippet 'https://github.com/asdf-vm/asdf/blob/master/completions/_asdf'
zinit snippet 'https://github.com/junegunn/fzf/blob/master/shell/completion.zsh'
zinit light chitoku-k/fzf-zsh-completions
zinit snippet 'https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh'
else
command -v git &>/dev/null \
&& git clone --depth=5 https://github.com/zdharma-continuum/zinit "${zinit_home}/bin"
fi
################################
# fzf
################################
export FZF_DEFAULT_OPTS="--extended --cycle --reverse --height=40% --ansi"
export FZF_COMPLETION_OPTS=""
export FZF_COMPLETION_TRIGGER=""
bindkey '^F' fzf-completion
#### command complete
# _fzf_dir_completion
# fd .
# }
_fzf_complete_make() {
_fzf_complete -m --preview 'echo {}' --preview-window down:3:wrap --min-height 15 -- "$@" < <(
command make help
)
}
_fzf_complete_make_post() {
awk '{print $1}'
}
#### history
_fzf_select_history_widget() {
BUFFER="$(history | perl -e 'print reverse <>' |
perl -pe 's/^\s*\d+\*?\s+//' |
awk '!a[$0]++ && length<256' |
fzf --height=40% --scheme=history --no-sort --query "$LBUFFER" |
sed 's/\\n/\n/')"
CURSOR=$#BUFFER # cursor move to line end
zle reset-prompt
}
zle -N _fzf_select_history_widget
bindkey '^R' _fzf_select_history_widget
#### kungfu
_fzf_default_completion() {
BUFFER="$(
cat ~/.config/kungfu/scroll.sh |
perl -ne 'print if !/^(#|$)/' |
perl -pe 's/(## .+)/\e[0;32m\1\e[0m/' |
fzf --preview='echo {} | perl -pe "s/^(.+)\s*(## .+)/\\2\n\\1/; s/;;/\n##/g;"' \
--preview-window='down:~10:wrap' \
--min-height 15 \
--height ~80% \
--scheme=history \
--query "$LBUFFER" |
perl -pe 's/## .+?$//'
)"
CURSOR=$#BUFFER
zle reset-prompt
}
zle -N _fzf_default_completion
export fzf_default_completion=_fzf_default_completion
#### kungfu pipe
_fzf_pipe_complete_post() { perl -pe 's/## .+?$//' }
_fzf_pipe_complete() {
_fzf_complete -m --scheme=history --preview 'echo {} | perl -pe "s/^(.+)(\s+## .+)/\\2\n\\1/"' --preview-window down:3:wrap --min-height 15 -- "$@" < <(
cat ~/.config/kungfu/scroll.sh |
perl -ne 'print if !/^(#|$)/ && /^\|/' |
perl -pe 's/(## .+)/\e[0;32m\1\e[0m/'
)
}
#### kungfu sub
_fzf_sub_complete_post() { perl -pe 's/## .+?$//' }
_fzf_sub_complete() {
_fzf_complete -m --scheme=history --preview 'echo {} | perl -pe "s/^(.+)(\s+## .+)/\\2\n\\1/"' --preview-window down:3:wrap --min-height 15 -- "$@" < <(
cat ~/.config/kungfu/scroll.sh |
perl -ne 'print if !/^(#|$)/ && /^\$\(/' |
perl -pe 's/(## .+)/\e[0;32m\1\e[0m/'
)
}
#### command complete
_fzf_command_complete_g_post() { awk '{ print $2 }' }
_fzf_command_complete_g() {
_fzf_complete -m --preview 'echo {}' --preview-window down:3:wrap --min-height 15 -- "$@" < <(
command git status --short
)
}
_fzf_command_complete_gb_post() { perl -pe 's/^\*//' | awk '{print $2}' }
_fzf_command_complete_gb() {
_fzf_complete -m --preview 'echo {}' --tac --preview-window down:3:wrap --min-height 15 -- "$@" < <(
git for-each-ref --sort=committerdate refs/heads/ --color=always \
--format="%(HEAD) %(color:green)%(committerdate:short)%(color:reset) %09 %(color:yellow)%(refname:short)%(color:reset) %09 %(authorname) %09 %(contents:subject)" \
| column -t -s $'\t'
)
}
_fzf_command_complete_di_post() { awk '{ print $3 }' }
_fzf_command_complete_di() {
_fzf_complete -m --preview 'echo {} | awk "{print $3}" | xargs docker image inspect' --preview-window right:40%:wrap --min-height 15 -- "$@" < <(
command docker images
)
}
_fzf_command_complete_dc_post() { awk '{ print $1 }' }
_fzf_command_complete_dc() {
_fzf_complete -m --preview 'echo {}' --preview-window down:3:wrap --min-height 15 -- "$@" < <(
command docker container ls
)
}
_fzf_command_complete_rise_dir() {
_fzf_complete -m --preview 'ls {}' --preview-window down:3:wrap --min-height 15 -- "$@" < <(
perl -e "
chomp(\$dir = qx(pwd));
chomp(\$dir = qx(dirname \$dir)) for (1..2);
print qq(\$dir\n) and chomp(\$dir = qx(dirname \$dir)) while \$dir ne qq(/)"
)
}
_fzf_my_completion_hook() {
local prefix lbuf
prefix=$1
lbuf=$2
if [[ "$prefix" == "|" ]]; then
prefix="" eval _fzf_pipe_complete ${(q)lbuf}
elif [[ "$prefix" == "\$(" ]]; then
prefix="" eval _fzf_sub_complete ${(q)lbuf}
elif [[ "$prefix" == .. ]]; then
prefix="" eval _fzf_command_complete_rise_dir ${(q)lbuf}
elif [[ "$prefix" == :* ]]; then
# TODO: typing -> :g -> c-f 동작이 불편, : 말고 다른 단어가 필요. gst+c-f?
# - :l + c-f => current ls
if eval "type _fzf_command_complete_${prefix#*:} > /dev/null"; then
prefix="" eval _fzf_command_complete_${prefix#*:} ${(q)lbuf}
else
return 1
fi
else
return 1 # default fail
fi
}
#### overwrite completion
# https://github.com/junegunn/fzf/blob/master/shell/completion.zsh#L264
fzf-completion() {
local tokens cmd prefix trigger tail matches lbuf d_cmds
setopt localoptions noshwordsplit noksh_arrays noposixbuiltins
# http://zsh.sourceforge.net/FAQ/zshfaq03.html
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
tokens=(${(z)LBUFFER})
if [ ${#tokens} -lt 1 ]; then
zle ${fzf_default_completion:-expand-or-complete}
return
fi
cmd=$(__fzf_extract_command "$LBUFFER")
# Explicitly allow for empty trigger.
trigger=${FZF_COMPLETION_TRIGGER-'**'}
[ -z "$trigger" -a ${LBUFFER[-1]} = ' ' ] && tokens+=("")
# When the trigger starts with ';', it becomes a separate token
if [[ ${LBUFFER} = *"${tokens[-2]-}${tokens[-1]}" ]]; then
tokens[-2]="${tokens[-2]-}${tokens[-1]}"
tokens=(${tokens[0,-2]})
fi
lbuf=$LBUFFER
tail=${LBUFFER:$(( ${#LBUFFER} - ${#trigger} ))}
# Trigger sequence given
# if [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then
if [[ ${#tokens} -gt 1 && ( "$tail" == "$trigger" || "$tail" == :* ) ]]; then
d_cmds=(${=FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir})
[ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}
[ -n "${tokens[-1]}" ] && lbuf=${lbuf:0:-${#tokens[-1]}}
if _fzf_my_completion_hook "$prefix" "$lbuf"; then
zle reset-prompt
elif eval "type _fzf_complete_${cmd} > /dev/null"; then
prefix="$prefix" eval _fzf_complete_${cmd} ${(q)lbuf}
zle reset-prompt
elif [ ${d_cmds[(i)$cmd]} -le ${#d_cmds} ]; then
_fzf_dir_completion "$prefix" "$lbuf"
else
_fzf_path_completion "$prefix" "$lbuf"
fi
# Fall back to default completion
else
zle ${fzf_default_completion:-expand-or-complete}
fi
}
neofetch
# BEGIN opam configuration
# This is useful if you're using opam as it adds:
# - the correct directories to the PATH
# - auto-completion for the opam binary
# This section can be safely removed at any time if needed.
[[ ! -r '/Users/kodingwarrior/.opam/opam-init/init.zsh' ]] || source '/Users/kodingwarrior/.opam/opam-init/init.zsh' > /dev/null 2> /dev/null
# END opam configuration
eval $(opam env)
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh