-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot_zshrc.tmpl
executable file
·339 lines (306 loc) · 10.7 KB
/
dot_zshrc.tmpl
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
# cSpell:disable
#--------------------------------------------------------------
# zsh
#--------------------------------------------------------------
export WORDCHARS="*?_-.[]~&;=!#$%^(){}<>"
export EDITOR=vim
export VIMINIT='let $MYVIMRC="~/.config/vim/.vimrc" | source $MYVIMRC'
# jobsの数を表示、%(1j.true.false):三項式、1j:jobs数が1以上でtrue
number_of_jobs="%(1j.%F{208}(%f%F{226}%B%j%b%F{208})%f.)"
# 終了ステータスを表示、0?:終了ステータスが0でtrue、%#:ユーザ種別
exit_status="%(0?.%F{002}.%F{001})%#%f"
# ディレクトリ表示、%F{}%f:色の指定、%B{}%b:太文字、%~:$HOMEからのパス
directory="%B%F{6}%~%f%b"
# 時刻表示、%D{format}:日付、%*:時刻(秒付)
# datetime="[%D{%m/%d} %*]"
# python、venv表示
if [ -n "$VIRTUAL_ENV" ]; then
PYTHON_VIRTUAL_ENV="($(basename $VIRTUAL_ENV))"
else
PYTHON_VIRTUAL_ENV=""
fi
# nix-shell表示
if [ -n "$IN_NIX_SHELL" ]; then
IN_NIX_SHELL="[nix-shell]"
else
IN_NIX_SHELL=""
fi
# プロンプト
MAINPROMPT="${IN_NIX_SHELL}${PYTHON_VIRTUAL_ENV}${directory}${number_of_jobs} ${exit_status} "
# プロンプトの設定
PROMPT="
${MAINPROMPT}"
# zsh_historyの保存先
mkdir -p "$HOME/.local/state/zsh" 2>/dev/null
export HISTFILE="$HOME/.local/state/zsh/.zsh_history"
# zshプロセスのメモリ上に保存される履歴の件数
HISTSIZE=10000
# ファイルに保存される履歴の件数
SAVEHIST=100000
# 同時に起動したzsh間でヒストリを共有
setopt share_history
# コマンドがリスト内で重複するの場合、古い方を削除
setopt hist_ignore_all_dups
# コマンドが前のイベントと重複する場合はリストに加えない
setopt hist_ignore_dups
# スペースで始まるコマンド行はヒストリから削除
setopt hist_ignore_space
# 余分な空白は詰めて記録
setopt hist_reduce_blanks
# ファイル書出の際、新しいコマンドと寿福する古いコマンドは無視
setopt hist_save_no_dups
zstyle ':completion:*:default' menu select=1
# makeコマンド補完
zstyle ':completion:*:make:*:targets' call-command true
zstyle ':completion:*:*:make:*' tag-order 'targets'
# 端末ラインのキーバインド設定
{{ if eq .chezmoi.os "darwin" -}}
# ctrl + dは無効
stty eof undef
# ctrl + qは無効
stty start undef
# ctrl + sは無効
stty stop undef
# ctrl + zはsuspend
stty susp ^Z
{{ else }}
# NOTE:sttyを変更するのは要注意
# alt + shift + cはinterrupt
# stty intr "^[C"
# alt + shift + zはsuspend
# stty susp "^[Z"
stty susp undef
{{- end }}
# キーバインドをemacs風にする
# bindkey -e
# キーバインドをvi風にする
bindkey -v
{{ if eq .chezmoi.os "darwin" -}}
# viinsのkeymapにemacsのコマンドを設定
bindkey -M viins '^A' beginning-of-line
bindkey -M viins '^B' backward-char
bindkey -M viins '^E' end-of-line
bindkey -M viins '^F' forward-char
bindkey -M viins '^H' backward-delete-char
bindkey -M viins '^K' kill-line
bindkey -M viins '^N' history-search-forward
bindkey -M viins '^P' history-search-backward
bindkey -M viins '^U' backward-kill-line
bindkey -M viins '^Xv' quoted-insert
bindkey -M viins '^W' backward-kill-word
{{ else }}
# ctrl-modifierのkeymapを削除
bindkey -M viins -r "^@"
bindkey -M viins -r "^A"
bindkey -M viins -r "^B"
bindkey -M viins -r "^C"
bindkey -M viins -r "^D"
bindkey -M viins -r "^E"
bindkey -M viins -r "^F"
bindkey -M viins -r "^G"
bindkey -M viins -r "^H"
bindkey -M viins -r "^I"
bindkey -M viins -r "^J"
bindkey -M viins -r "^K"
bindkey -M viins -r "^L"
bindkey -M viins -r "^M"
bindkey -M viins -r "^N"
bindkey -M viins -r "^O"
bindkey -M viins -r "^P"
bindkey -M viins -r "^Q"
bindkey -M viins -r "^Q^A"
bindkey -M viins -r "^Q^G"
bindkey -M viins -r "^Q^Q"
bindkey -M viins -r "^Q^W"
bindkey -M viins -r "^Q^X"
bindkey -M viins -r "^Q^Z"
bindkey -M viins -r "^R"
bindkey -M viins -r "^S"
bindkey -M viins -r "^T"
bindkey -M viins -r "^U"
bindkey -M viins -r "^V"
bindkey -M viins -r "^W"
bindkey -M viins -r "^X^R"
bindkey -M viins -r "^X?"
bindkey -M viins -r "^XC"
bindkey -M viins -r "^Xa"
bindkey -M viins -r "^Xc"
bindkey -M viins -r "^Xd"
bindkey -M viins -r "^Xe"
bindkey -M viins -r "^Xh"
bindkey -M viins -r "^Xm"
bindkey -M viins -r "^Xn"
bindkey -M viins -r "^Xt"
bindkey -M viins -r "^Xv"
bindkey -M viins -r "^X~"
bindkey -M viins -r "^Y"
bindkey -M viins -r "^Z"
# viinsのkeymapにemacsのコマンドを設定(shift + alt-modifier)
bindkey -M viins '^[A' beginning-of-line
bindkey -M viins '^[B' backward-char
bindkey -M viins '^[E' end-of-line
bindkey -M viins '^[F' forward-char
bindkey -M viins '^[H' backward-delete-char
bindkey -M viins '^[K' kill-line
bindkey -M viins '^[N' history-search-forward
bindkey -M viins '^[P' history-search-backward
bindkey -M viins '^[U' backward-kill-line
bindkey -M viins '^[Xv' quoted-insert
bindkey -M viins '^[W' backward-kill-word
{{- end }}
# shift + Tabで逆Tab方向に移動
bindkey '^[[Z' reverse-menu-complete
# option(alt) + ←→で単語毎のカーソル移動
bindkey "^[[1;3C" forward-word
bindkey -M vicmd "^[[1;3C" forward-word
bindkey "^[[1;3D" backward-word
bindkey -M vicmd "^[[1;3D" backward-word
# option + ←→で単語毎のカーソル移動(rio)
bindkey "^[f" forward-word
bindkey -M vicmd "^[f" forward-word
bindkey "^[b" backward-word
bindkey -M vicmd "^[b" backward-word
# option(alt) + shift + ←で単語毎の削除
bindkey "^[[1;4D" backward-kill-word
# 上がうまくいかなかった時のカスタム関数
# my-backward-kill-word() {
# zle backward-kill-word &&
# zle backward-delete-char
# }
# zle -N my-backward-kill-word
# bindkey "^[[1;4D" my-backward-kill-word
{{ if eq .chezmoi.os "darwin" -}}
# ctrl + p/nをhistory-search-xxxに変更
bindkey "^N" history-search-forward
bindkey "^P" history-search-backward
{{ else }}
# alt + shift + p/nをhistory-search-xxxに変更
bindkey "^[N" history-search-forward
bindkey "^[P" history-search-backward
{{- end }}
#--------------------------------------------------------------
# plugin
#--------------------------------------------------------------
### Added by Zinit's installer
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
print -P "%F{33} %F{34}Installation successful.%f%b" || \
print -P "%F{160} The clone has failed.%f%b"
fi
source "$HOME/.local/share/zinit/zinit.git/zinit.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
# zinit light-mode for \
# from"gh-r" nocompile sbin src"init.zsh" \
# atclone"./starship init zsh > init.zsh; ./starship completions zsh > _starship" \
# starship/starship
#--------------------------------------------------------------
# zsh-vimode-visual
#--------------------------------------------------------------
zinit light-mode for \
@'b4b4r07/zsh-vimode-visual'
# 選択範囲を{}で囲うように置き換え
vi-visual-surround-curlybrackets()
{
zle vi-visual-kill
BUFFER="$LBUFFER{$CUTBUFFER}$RBUFFER"
zle vi-visual-exit
}
zle -N vi-visual-surround-curlybrackets
# Escでvi-visual-modeに入る
bindkey '^[' vi-visual-exit
# vでカーソル位置リセット(vi-visual-modeに入り直す)
bindkey -M vivis 'v' vi-visual-mode
# iでviinsモードに入る
bindkey -M vivis "i" vi-insert
# spaceで選択範囲をスペースで囲うように置き換える
bindkey -M vivis " " vi-visual-surround-space
# 'で選択範囲シングルクォートで囲うように置き換える
bindkey -M vivis "'" vi-visual-surround-squote
# "で選択範囲ダブルクォートで囲うように置き換える
bindkey -M vivis "\"" vi-visual-surround-dquote
# ()で選択範囲()で囲うように置き換える
bindkey -M vivis "(" vi-visual-surround-parenthesis
bindkey -M vivis ")" vi-visual-surround-parenthesis
# {}で選択範囲{}で囲うように置き換える
bindkey -M vivis "{" vi-visual-surround-curlybrackets
bindkey -M vivis "}" vi-visual-surround-curlybrackets
# option(alt) + ←→で単語毎のカーソル移動
bindkey -M vivis "^[[1;3C" vi-visual-forward-word
bindkey -M vivis "^[[1;3D" vi-visual-backward-word
terminfo_down_sc=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1]
left_down_prompt_preexec() {
print -rn -- $terminfo[el]
}
add-zsh-hook preexec left_down_prompt_preexec
function zle-keymap-select zle-line-init zle-line-finish
{
case $KEYMAP in
main|viins)
# PROMPT_2="$fg[white]-- INSERT --$reset_color"
PROMPT_2=""
;;
vicmd)
PROMPT_2="$fg[green]-- NORMAL --$reset_color"
;;
vivis|vivli)
PROMPT_2="$fg[yellow]-- VISUAL --$reset_color"
;;
esac
# %{$terminfo_down_sc$PROMPT_2$terminfo[rc]% で下にstatus表示
PROMPT="
%{$terminfo_down_sc$PROMPT_2$terminfo[rc]%}${MAINPROMPT}"
zle reset-prompt
}
zle -N zle-line-init
zle -N zle-line-finish
zle -N zle-keymap-select
zle -N edit-command-line
#--------------------------------------------------------------
# terminal
#--------------------------------------------------------------
# launch tmux when start zsh
if { [ "$TERM" = "alacritty" ] || [ "$TERM" = "rio" ] } && command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
tmux attach || tmux
fi
{{ if eq .chezmoi.os "darwin" -}}
# iTerm2
tab-color() {
echo -ne "\033]6;1;bg;red;brightness;$1\a"
echo -ne "\033]6;1;bg;green;brightness;$2\a"
echo -ne "\033]6;1;bg;blue;brightness;$3\a"
}
tab-reset() {
echo -ne "\033]6;1;bg;*;default\a"
}
chpwd() {
if [ "$TERM" = "xterm-256color" ]; then
case $PWD/ in
~) tab-color 0 200 0;;
*) tab-reset;;
esac
echo -ne "\033]0;$(pwd | rev | awk -F \/ '{print "/"$1"/"$2}'| rev)\007"
fi
if [ "$TERM" = "screen-256color" ]; then
case $PWD in
~) tmux set-option -w window-status-format '#[bg=#008000] #I #{b:pane_current_path} ' ;;
*) tmux set-option -w window-status-format '#[bg=#808080] #I #{b:pane_current_path} ' ;;
esac
fi
}
{{- end }}
#--------------------------------------------------------------
# other
#--------------------------------------------------------------
# .zshrc.lazyを遅延読み込み
zinit wait lucid light-mode as'null' \
atinit'source "${HOME}/.zshrc.lazy"' \
for @'zdharma-continuum/null'