-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
428 lines (368 loc) · 11.6 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# My zshrc
#
# vim: set ts=2 sw=2 sts=0 expandtab:
# DEBUG: https://stevenvanbael.com/profiling-zsh-startup
#zmodload zsh/zprof
export TERM="xterm-256color"
export XDG_CONFIG_HOME=$HOME/.config
export XDG_CACHE_HOME=$HOME/.cache
export EDITOR=vi
export LESS="-XRF --shift 8 --LONG-PROMPT"
path=( $HOME/.local/bin(N-/) $HOME/bin(N-/) $path )
case ${OSTYPE} in
darwin*)
if [[ "arm64" == "$(uname -m)" ]]; then
brew_root=/opt/homebrew
else
brew_root=/usr/local
fi
manpath=(
$brew_root/opt/coreutils/libexec/gnuman(N-/)
$brew_root/opt/findutils/libexec/gnuman(N-/)
$brew_root/opt/gnu-sed/libexec/gnuman(N-/)
$brew_root/opt/gnu-tar/libexec/gnuman(N-/)
$brew_root/opt/gnu-time/libexec/gnuman(N-/)
$brew_root/opt/gnu-which/libexec/gnuman(N-/)
$brew_root/opt/grep/libexec/gnuman(N-/)
$manpath
)
path=(
$brew_root/bin(N-/)
$brew_root/sbin(N-/)
$brew_root/opt/apr/bin(N-/)
$brew_root/opt/avr-gcc@11/bin(N-/)
$brew_root/opt/avr-gcc@9/bin(N-/)
$brew_root/opt/avr-gcc@8/bin(N-/)
$brew_root/opt/gawk/libexec/gnubin(N-/)
$brew_root/opt/berkeley-db@4/bin(N-/)
$brew_root/opt/binutils/bin(N-/)
$brew_root/opt/bison/bin(N-/)
$brew_root/opt/bzip2/bin(N-/)
$brew_root/opt/coreutils/libexec/gnubin(N-/)
$brew_root/opt/curl/bin(N-/)
$brew_root/opt/curl-openssl/bin(N-/)
$brew_root/opt/findutils/libexec/gnubin(N-/)
$brew_root/opt/gcc/bin(N-/)
$brew_root/opt/gettext/bin(N-/)
$brew_root/opt/git/share/git-core/contrib/diff-highlight(N-/)
$brew_root/opt/gnu-sed/libexec/gnubin(N-/)
$brew_root/opt/gnu-tar/libexec/gnubin(N-/)
$brew_root/opt/gnu-time/libexec/gnubin(N-/)
$brew_root/opt/gnu-which/libexec/gnubin(N-/)
$brew_root/opt/go/bin(N-/)
$brew_root/opt/grep/libexec/gnubin(N-/)
$brew_root/opt/icu4c/bin(N-/)
$brew_root/opt/icu4c/sbin(N-/)
$brew_root/opt/libarchive/bin(N-/)
$brew_root/opt/libpq/bin(N-/)
$brew_root/opt/libressl/bin(N-/)
$brew_root/opt/libxml2/bin(N-/)
$brew_root/opt/libxslt/bin(N-/)
$brew_root/opt/llvm/bin(N-/)
$brew_root/opt/ncurses/bin(N-/)
$brew_root/opt/make/libexec/gnubin(N-/)
$brew_root/opt/mysql-client/bin(N-/)
$brew_root/opt/openjdk/bin(N-/)
$brew_root/opt/openldap/bin(N-/)
$brew_root/opt/openldap/sbin(N-/)
$brew_root/opt/openssl@3/bin(N-/)
$brew_root/opt/qmk/bin/(N-/)
$brew_root/opt/sqlite/bin(N-/)
$path
)
fpath=( $brew_root/share/zsh/site-functions(N-/) $fpath )
export HOMEBREW_NO_AUTO_UPDATE=1
export CURL_CONFIG=$brew_root/opt/curl/bin/curl-config(N-/)
export GROOVY_HOME=$brew_root/opt/groovy/libexec(N-/)
;;
esac
# Dark / Light
local system_appearance=${$(defaults read -g AppleInterfaceStyle 2>/dev/null):-Light}
bindkey -e
alias k='kubectl'
alias -g g='git'
alias -g p='git add -p'
alias mm='git master && git souji && git-delete-squashed-branches'
alias master='git master && git souji && git-delete-squashed-branches'
alias lg='lazygit'
alias gg='git grep'
alias gl='git grep -l'
alias git-tree='git tree | tree --fromfile | bat -p'
alias gt='gtree'
alias h='git hist origin/$(git default)^..@'
alias hn='git hist --name-only origin/$(git default)^..@'
alias pu='git push -u origin $(git branch --show-current)'
alias pf='git push --force-with-lease --force-if-includes'
alias pushu='git push -u origin $(git symbolic-ref --short HEAD)'
alias pushf='git push --force-with-lease --force-if-includes'
alias br='git br'
alias bra='git bra'
alias ci='git commit'
alias cim='git commit -m'
alias co='git switch'
alias cob='git cob'
alias di='git --no-pager di'
alias dic='git --no-pager dic'
alias fv='git fv'
alias hist="git hist"
alias pv='git pv'
alias s='git status -sb'
alias st='git status'
alias ec="editorconfig-checker" # for nvim-mason-null-ls
alias lazygit="lazygit --use-config-dir ~/.config/lazygit"
function i() { # install-for-current-dir
if [ -f "$PWD/.tool-versions" ]; then (set -x; mise install -y); fi
if [ -f "$PWD/.lefthook.yml" ]; then (set -x; lefthook install); fi
if [ -f "$PWD/rust-toolchain.toml" ]; then (set -x; rustup update); fi
if [ -f "$PWD/bun.lockb" ]; then
(set -x; bun install)
elif [ -f "$PWD/package-lock.json" ]; then
(set -x; npm ci)
fi
}
# ls using https://github.com/Peltoche/lsd
if (( $+commands[lsd] )); then
alias ls='lsd'
alias l='lsd -l'
alias ll='lsd -l'
alias la='lsd -la'
alias al='lsd -la'
else
alias ls="ls -G"
alias l='ls -l'
alias ll='ls -l'
alias la='ls -al'
fi
setopt auto_cd
setopt auto_pushd
setopt no_beep
setopt interactive_comments
#######
# zinit
#######
case ${OSTYPE} in
darwin*)
# zinit installed by homebrew
source $brew_root/opt/zinit/zinit.zsh
;;
linux*)
if [ ! -d ~/.zinit ]; then
bash -c "$(curl --fail --show-error --silent --location https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)"
fi
source $HOME/.zinit/bin/zinit.zsh
;;
esac
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
zinit wait lucid atload'_zsh_autosuggest_start' light-mode for zsh-users/zsh-autosuggestions
zinit ice wait
zinit light zsh-users/zsh-syntax-highlighting
# https://qiita.com/mollifier/items/81b18c012d7841ab33c3
#zinit light mollifier/anyframe
zinit ice wait as'program' pick'bin/git-dsf'
case ${OSTYPE} in
darwin*)
;;
linux*)
zinit snippet OMZ::plugins/gnu-utils/gnu-utils.plugin.zsh
;;
esac
# [Theme]
# https://github.com/zdharma-continuum/zinit#plugins-and-snippets
zinit ice as"command" from"gh-r" \
atclone"./starship init zsh > init.zsh; ./starship completions zsh > _starship" \
atpull"%atclone" src"init.zsh"
zinit light starship/starship
###########
# WordChars
###########
export WORDCHARS=' *?.[]~-=&;!#$%^(){}<>/|,'
autoload -Uz select-word-style
select-word-style default
zstyle ':zle:*' word-chars $WORDCHARS
zstyle ':zle:*' word-style unspecified
#########
# History
#########
HISTORY_IGNORE="(pwd|l[sal]|exit|mm|kill|pu)"
HISTFILE=$HOME/.zsh-history
HISTSIZE=25000
SAVEHIST=25000
HISTTIMEFORMAT='%Y-%m-%d %H:%M:%S '
setopt share_history
setopt inc_append_history
setopt hist_expire_dups_first
setopt hist_ignore_all_dups
setopt hist_ignore_dups
setopt hist_reduce_blanks
#setopt hist_no_store
setopt EXTENDED_HISTORY
function fzf-select-history() {
BUFFER=$(history -n -r 1 | fzf --no-sort --query "$LBUFFER")
CURSOR=$#BUFFER
zle reset-prompt
}
zle -N fzf-select-history
bindkey '^r' fzf-select-history
function fzf-cdr() {
local selected_dir=$(cdr -l | awk '{ print $2 }' | fzf)
if [ -n "$selected_dir" ]; then
BUFFER="cd ${selected_dir}"
zle accept-line
fi
zle clear-screen
}
zle -N fzf-cdr
setopt noflowcontrol
bindkey '^q' fzf-cdr
#####################
# CommandLine Tool(s)
#####################
# https://github.com/junegunn/fzf#environment-variables
export FZF_DEFAULT_OPTS="--layout=reverse --inline-info"
if (( $+commands[direnv] )); then eval "$(direnv hook zsh)"; fi
if (( $+commands[mise] )); then
eval "$(mise activate zsh)"
alias asdf=mise
alias mx="mise x --"
fi
# bat (Powerful & Colorful commands)
if (( $+commands[bat] )); then
# https://github.com/sharkdp/bat
alias c='bat'
export BAT_THEME="Monokai Extended ${system_appearance}"
export BAT_PAGER="less -XRF --shift 4 --LONG-PROMPT"
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
fi
# lsd (next gen ls command)
if [ -d $XDG_CONFIG_HOME/lsd ]; then
(cd $XDG_CONFIG_HOME/lsd/ && ln -sf ./colors-${(L)system_appearance}.yaml ./colors.yaml)
fi
###########
# Languages
###########
if (( $+commands[go] )); then
export GOPATH=$HOME
export GOROOT=$(go env GOROOT);
path=($(go env GOPATH)/bin(N-/) $path)
fi
if (( $+commands[rye] )); then
test -f ~/.rye/env || rye self install -y
source ~/.rye/env
fi
if (( $+commands[composer] )); then
path=($HOME/.composer/vendor/bin(N-/) $path)
fi
if (( $+commands[plenv] )); then
eval "$(plenv init - zsh)"
export PERL_MB_OPT="--install_base \"~/perl5\""
export PERL_MM_OPT="INSTALL_BASE=~/perl5"
fi
# rust
[ ! -f "$HOME/.cargo/env" ] || . "$HOME/.cargo/env"
#####
# Git
#####
bindkey '^O' move_ghq_directories
bindkey '^G' select-git-branch
move_ghq_directories() {
selected=`ghq list | fzf --query "$LBUFFER"`
if [ -n "${#selected}" ]; then
target_dir="`ghq root`/$selected"
echo "cd $target_dir"
BUFFER="cd $target_dir"
zle accept-line
fi
zle clear-screen
}
zle -N move_ghq_directories
select-git-branch() {
git branch -a --sort=-authordate |
grep -v -e '->' -e '*' |
perl -pe 's/^\h+//g' |
perl -pe 's#^remotes/origin/###' |
perl -nle 'print if !$c{$_}++' |
fzf |
xargs git checkout
}
zle -N select-git-branch
##################
# Kubernates (k8s)
##################
# Currently I'm not using k8s
#if (( $+commands[kubectl] )); then
# alias kc=kubectl
#fi
#####
# AWS
#####
if (( $+commands[copilot] )); then source <(copilot completion zsh); fi
############
# gcloud SDK
############
case ${OSTYPE} in
darwin*)
source "$(brew --prefix)/share/google-cloud-sdk/completion.zsh.inc"
source "$(brew --prefix)/share/google-cloud-sdk/path.zsh.inc"
;;
linux*)
;;
esac
##################
# Local dependency
##################
if [ -f ~/.secrets/.zshrc.local ]; then
source ~/.secrets/.zshrc.local
fi
if [ "$DOTFILES/.secrets/.zshrc.local" -nt "~/.secrets/.zshrc.local.zwc" ]; then
zcompile ~/.zshrc.local
fi
if [ "$DOTFILES/.zshrc" -nt "~/.zshrc.zwc" ]; then
zcompile ~/.zshrc
fi
#############
# Completions
#############
setopt complete_in_word # カーソル位置で補完する。
#setopt auto_param_slash # ディレクトリ名の補完で末尾の / を自動的に付加し、次の補完に備える
setopt glob_complete # globを展開しないで候補の一覧から補完する。
setopt magic_equal_subst # コマンドラインの引数で --prefix=/usr などの = 以降でも補完できる
setopt globdots # 明確なドットの指定なしで.から始まるファイルをマッチ
zstyle ':completion:*' completer _complete
# Select complations list like emacs
zstyle ':completion:*:default' menu select=1
# Coloring for completion candidates
zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' '+l:|=* r:|=*'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' keep-prefix
zstyle ':completion:*' recent-dirs-insert both
zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin
# 補完関数の表示を過剰にする編
zstyle ':completion:*' verbose yes
zstyle ':completion:*' completer _expand _complete _match _prefix _approximate _list _history
zstyle ':completion:*:messages' format $YELLOW'%d'$DEFAULT
#zstyle ':completion:*:warnings' format $RED'No matches for:'$YELLOW' %d'$DEFAULT
#zstyle ':completion:*:descriptions' format $YELLOW'completing %B%d%b'$DEFAULT
#zstyle ':completion:*:corrections' format $YELLOW'%B%d '$RED'(errors: %e)%b'$DEFAULT
zstyle ':completion:*:options' description 'yes'
if (( $+commands[brew] )); then
mkdir -p ~/.zfunc
fpath+=~/.zfunc
if [ ! -e ~/.zfunc/_rustup -a $+commands[rustup] ]; then
rustup completions zsh > ~/.zfunc/_rustup
fi
fi
autoload -Uz compinit
compinit -C
if (( $+commands[gh] )); then eval "$(gh completion -s zsh)"; fi
if (( $+commands[kubectl] )); then source <(kubectl completion zsh); fi
##################
# End of execution
##################
typeset -T LD_LIBRARY_PATH ld_library_path
typeset -U ld_library_path
typeset -T LIBRARY_PATH library_path
typeset -U library_path
typeset -U path PATH
# DEBUG: https://stevenvanbael.com/profiling-zsh-startup
#zprof