-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.zshrc
402 lines (337 loc) · 10.9 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
# =======================================================
#
# Initial setup file for only interactive zsh
# This file is read after .zshenv file is read.
#
# =======================================================
# ===== default autoloads =====
# U option is disable to open alias, in loading functions.
## Enable appoint color on name
autoload -Uz colors
colors
## Enable zmv command
autoload zmv
alias zmv='noglob zmv -W'
# enable cdr {{{
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':completion:*' recent-dirs-insert both
zstyle ':chpwd:*' recent-dirs-max 500
zstyle ':chpwd:*' recent-dirs-default true
zstyle ':chpwd:*' recent-dirs-file "${XDG_CACHE_HOME:-$HOME/.cache}/shell/chpwd-recent-dirs"
zstyle ':chpwd:*' recent-dirs-pushd true
# }}}
## call version check function
autoload -Uz is-at-least
## zsh editor
#autoload zed
# prediction Completion
autoload predict-on
# predict-off
# OS ごとのfunction, プラグイン {{{
case "${OSTYPE}" in
freebsd*|darwin*)
source ~/.zsh/.zrc.mac
;;
linux*)
source ~/.zsh/.zrc.linux
;;
cygwin*)
source ~/.zsh/.zrc.cyg
;;
esac
# ---- }}}
### Command Completemente{{{
# Default Completement
# fpathの変更はcompinitを実行する前に行わないと意味がないので注意!
autoload -U compinit; compinit
# }}}
# 補完方法の設定 指定した順番に実行
### _oldlist 前回の補完結果を再利用する。
### _complete: fpath補完
### _expand: globや変数の展開を行う
### _match: globを展開しないで候補の一覧から補完する。
### _history: ヒストリのコマンドも補完候補とする。
### _ignored: 補完候補にださないと指定したものも補完候補とする。
### _approximate: 似ている補完候補も補完候補とする。
### _prefix: カーソル以降を無視してカーソル位置までで補完する。
zstyle ':completion:*' completer \
_oldlist _complete _expand _match _history _ignored _approximate _prefix
## sudo時にはsudo用のパスも使う。
zstyle ':completion:sudo:*' environ PATH="$SUDO_PATH:$PATH"
#補完候補がないときは、より曖昧検索パワーを高める
### r:|[._-]=*: 「.」「_」「-」の前にワイルドカード「*」があるものとして補完する。
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z} r:|[._-]=*'
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' use-cache true
# 詳細な情報を使う。
zstyle ':completion:*' verbose yes
# 補完リストをグループ分けする
zstyle ':completion:*' group-name ''
zstyle ':completion:*:default' menu select=2
zstyle ':completion:*:warnings' format 'No matches for: %d'
## via cdd formaat
zstyle ':completion:*:descriptions' format '%BCompleting%b %F{yellow}%U%d%u'
zstyle ':completion:*' list-separator '-->'
# ../ などとタイプしたとき、現在いるディレクトリを補完候補に出さない
zstyle ':completion:*' ignore-parents parent pwd ..
### }}}
### Set shell options{{{
## カレントディレクトリにサブディレクトリが見つからない場合にcdが検索する場所
#cdpath=($HOME)
setopt no_beep
setopt no_flow_control
setopt auto_menu
setopt auto_list
#glob展開の拡張(正規表現ライクな記法が使えるようになる)
setopt extended_glob
# 補完候補リストを出来るだけコンパクトに表示する
setopt list_packed
setopt list_types
# =以降も補完する(--prefix=/usrなど)
setopt magic_equal_subst
setopt print_eight_bit
setopt auto_cd
# stack cd history
setopt auto_pushd
setopt pushd_ignore_dups
setopt ignore_eof
# 明確に.指定なしで.から始まるファイル名を補完
setopt globdots
# use '#' as comment on commandloine
setopt interactive_comments
# コマンド実行後は右プロンプトを消す
#setopt transient_rprompt
# 右プロンプトがかぶったら消す(デフォルトONじゃね感)
setopt promptcr
# コマンドの終了コードが0以外の場合に表示
# setopt print_exit_value
# 該当するブレース{}展開が存在しない場合、ascii順にソートして展開する
setopt brace_ccl
## 補完実行時にエイリアスを展開せずにそのままのコマンドとしてエイリアスを扱う
#setopt complete_aliases # あると g で git が補完されなかったりしてうっとおしいだけなので無効
# ファイル名の補完時、ディレクトリにマッチしたら/を付与
setopt mark_dirs
# カッコの対応なども補完
setopt auto_param_keys
# correct slash of a end of name of dir
setopt auto_param_slash
# パスの最後の/を削除しない(勝手に削除されると困るケースもあるので)
setopt noautoremoveslash
# ファイル名一覧を順次表示
setopt always_last_prompt
# 補完候補リストが垂直ではなく水平方向に並ぶようになる
setopt list_rows_first
## 曖昧マッチよりも正確さを優先する?
#setopt rec_exact
# スペルミスを指摘して正しいと思われるコマンドを出してくれる 設定しない
setopt no_correct
setopt no_correctall
# バックグラウンドジョブのスピードを落とさない
setopt no_bg_nice
# ログアウトしてもバックグランドジョブを止めない
setopt no_hup
# ジョブが終了したらただちに知らせる
setopt notify
# rm * を実行する前に確認
setopt rm_star_wait
# }}}
# permission settings
umask 022
# Enable appoint on reserved-word in PROMPT
# ex: $UID $HOME
setopt prompt_subst
# mm?
# limit coredumpsize 0
# if there too many Completementes
export LISTMAX=0
# history settings{{{
HISTFILE=~/.zsh_histfile
# history in memory
HISTSIZE=1000000
# history in file
SAVEHIST=1000000
# disable to save hist, if it's on RootUser
if [ $UID = 0 ]; then
unset HISTFILE
SAVEHIST = 0
fi
# hook when commands registered to history
zshaddhistory() {
local line=${1%%$'\n'}
local cmd=${line%% *}
[[ ${#line} -ge 5
&& ${cmd} != (l|l[sal])
&& ${cmd} != (c|cd)
&& ${cmd} != (m|man)
&& ${cmd} != (hub)
]]
}
setopt share_history
setopt hist_ignore_all_dups # if there are overlaps on histfile, delete the old one
setopt hist_ignore_dups # disable to save histfile, if its overlaps on just before
setopt HIST_IGNORE_SPACE
# ignore `history` command itselfs
setopt hist_no_store
setopt hist_reduce_blanks
# ignore command is same as old one
setopt hist_save_no_dups
## 補完時にヒストリを自動的に展開する。
setopt hist_expand
setopt share_history
# when use zsh on multiwindow, add on a history file
setopt append_history
# append history immediately after commands finished.
setopt inc_append_history
# save Begin and End
setopt EXTENDED_HISTORY
setopt nonomatch
# --- 入力済みの文字列にマッチしたコマンドのヒストリを表示させる ---
autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^P" history-beginning-search-backward-end
bindkey "^N" history-beginning-search-forward-end
# ヒストリ呼び出しから、実行までの間に一度編集を可能にする
setopt hist_verify
# }}}
## 実行したプロセスの消費時間が3秒以上かかったら自動的に消費時間の統計情報を表示する。
REPORTTIME=3
# spell checks on commandline
# setopt corrent
######
# key binds setting {{{
#######
### Binding key ###
# Like vim
#bindkey -v
# Like Emacs
bindkey -e
# Ctrl-u delete line before cursor
bindkey '^U' backward-kill-line
# Ctrl-u delete word before cursor
bindkey "^[h" backward-kill-word
bindkey "^[u" undo
bindkey "^[r" redo
# }}}
# ------------------- load plugins ---------------- {{{
# -- zsh syntax highlight ---
source $BREW_PATH/opt/zsh-fast-syntax-highlighting/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
# -- zaw.zsh -------- (pecoが入んない環境のみ)
if which peco > /dev/null; then
echo 'use peco'
source ~/.zsh/.zrc.peco.zsh
function _insert_pecopipe() {
LBUFFER=${LBUFFER}" | peco"
}
zle -N _insert_pecopipe
bindkey '^[p' _insert_pecopipe
else
echo 'use zaw'
source ~/.zsh/modules/zaw/zaw.zsh
source ~/.zsh/.zrc.zaw.zsh
fi
# -- notify if command takes long time
source ~/.zsh/functions/notify_wlonger.zsh
# }}}
# -------------------- settings for plugins ------------ {{{
# {{{
function _delete-char-or-list-expand() {
if [[ -z "${RBUFFER}" ]]; then
# the cursor is at the end of the line
zle list-expand
else
zle delete-char
fi
}
zle -N _delete-char-or-list-expand
bindkey '^D' _delete-char-or-list-expand
# }}}
# }}}
# move dotfiles in Dropbox{{{
function dotf {
if [ $# != 0 ]; then # 引数が存在するならば
cd ~/Dropbox/dotfiles
vim $1
else
cd ~/Dropbox/dotfiles
fi
}
# }}}
#show buffer stack{{{
show_buffer_stack(){
POSTDISPLAY="
stacked: $LBUFFER"
zle push-line-or-edit
}
zle -N show_buffer_stack
# ^[ = ESC
bindkey "q" show_buffer_stack
# }}}
function cdup() {
echo
cd ..
zle reset-prompt
}
zle -N cdup
# Ctrl+] なんかとかぶったら考える
bindkey '^]' cdup
# }}}
# 全履歴の検索
function history-all { history -E 1 }
# --------
# complete sheet{{{
# ------------------
compdef _sheets sheet
function _sheets {
local -a cmds
_files -W ~/.sheets/ -P '~/.sheets/'
cmds=('list' 'edit' 'copy')
_describe -t commands "subcommand" cmds
return 1;
}
# }}}
# utils{{{
mkcd() {mkdir -p "$@" && cd "$*[-1]"}
mktmp() {mkdir `date +"%Y%m%d_%H%M%S"`}
showroot() { `git rev-parse --git-dir |sed -e "s/[^\/]*$//g"` }
DELI_ST_LT="%{${fg[green]}%}<%{${fg[reset_color]}%}"
DELI_ST_GT="%{${fg[green]}%}>%{${fg[reset_color]}%}"
CR_cyan="%{${fg[cyan]}%}"
# virtualenvを使っていれば、使っているsandboxの情報を出す
function put_virtualenv_info {
[ $VIRTUAL_ENV ] && echo "${DELI_ST_LT}%{${fg[blue]}%}venv: %{${fg[cyan]}%}`basename $VIRTUAL_ENV` $DELI_ST_GT"
}
# rbenvでアクチしているRubyのversionを表示する
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
function rbenv_version() {
if which rbenv > /dev/null; then
_ver="$CR_cyan`rbenv version | sed -e "s/\s(.\+$//g"`"
echo "${DELI_ST_LT}%{${fg[blue]}%}rbenv: $_ver ${DELI_ST_GT}"
else
echo ""
fi
}
# -------------- load prompt ---------------- {{{
source ~/.zsh/themes/hachibee.zsh-theme
# homeに自分で定義したLSCOLORがあれば、それで上書きする
if [ -f ~/.dir_colors ]; then
echo 'use local .dir_colors'
eval `dircolors ~/.dir_colors -b`
else
source ~/.zsh/themes/lscolors.default
fi
# }}}
hash -d drop=~/Dropbox/
if which direnv > /dev/null; then
eval "$(direnv hook zsh)"
fi
# Xserver for WSL2
if [ -e /mnt/wsl ]; then
echo "Detect WSL."
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
export LIBGL_ALWAYS_INDIRECT=1
fi
# load alias
source ~/.zsh/.zrc.alias