-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
366 lines (321 loc) · 11 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
# http://journal.mycom.co.jp/column/zsh/index.html
# http://www.clear-code.com/blog/2011/9/5.html
# http://www.gentei.org/~yuuji/support/zsh/files/zshrc
debug_echo "(begin) .zshrc"
# Set shell options
# 有効にしてあるのは副作用の少ないもの
setopt auto_name_dirs
setopt auto_param_keys
setopt auto_remove_slash
setopt extended_glob
setopt list_types
setopt no_beep
setopt sh_word_split
# 便利だが副作用の強いものはコメントアウト
#setopt auto_menu
#setopt correct
#setopt rm_star_silent
#setopt sun_keyboard_hack
autoload -Uz add-zsh-hook # hookを有効に。
# {{{ キー關聯
# http://www.clear-code.com/blog/2011/9/5.html
# EDITOR=vimだとviキーバインドになってしまう為、
# emacsキーバインドを使用するように明示。
bindkey -e
# }}}
# {{{ 補完關聯
# http://www.clear-code.com/blog/2011/9/5.html
# 補完システムを利用: 補完の挙動が分かりやすくなる2つの設定のみ記述
zstyle ':completion:*' format '%BCompleting %d%b'
zstyle ':completion:*' group-name ''
autoload -U compinit && compinit
# }}}
# 環境変数 {{{
export GOOS=$HOME/go
export GOPATH=$HOME/goenv
# }}}
# {{{ PATH
# http://www.clear-code.com/blog/2011/9/5.html
# 重複したパスを除外する
typeset -U path PATH
# (N-/): 存在しないディレクトリは登録しない。
# パス(...): ...という条件にマッチするパスのみ残す。
# N: NULL_GLOBオプションを設定。
# globがマッチしなかったり存在しないパスを無視する。
# -: シンボリックリンク先のパスを評価。
# /: ディレクトリのみ残す。
path=(
# ndenv
$HOME/.ndenv/bin(N-/)
$HOME/.ndenv/shims(N-/)
# go
$GOOS/bin(N-/)
$GOPATH/bin(N-/)
# anyenv
$HOME/.anyenv/bin(N-/)
$HOME/.hsenv/bin(N-/)
# cabal
$HOME/.cabal/bin(N-/)
$HOME/cabal-dev/bin(N-/)
# 自分用
$HOME/.local/bin(N-/)
$LOCALBIN(N-/)
# システム用
/usr/local/bin(N-/)
/usr/bin(N-/)
/bin(N-/)
$path
)
# }}}
# {{{ MANPATH
# http://www.clear-code.com/blog/2011/9/5.html
# 重複したパスを除外する
typeset -U manpath MANPATH
# (N-/) 存在しないディレクトリは登録しない。
# パス(...): ...という条件にマッチするパスのみ残す。
# N: NULL_GLOBオプションを設定。
# globがマッチしなかったり存在しないパスを無視する。
# -: シンボリックリンク先のパスを評価。
# /: ディレクトリのみ残す。
manpath=(
# 自分用
$HOME/.local/**/man(N-/)
$HOME/local/**/man(N-/)
# システム用
/usr/local/man(N-/)
/usr/man(N-/)
/usr/share/man(N-/)
/var/**/man(N-/)
$manpath
)
# }}}
# {{{ FPATH
# http://qiita.com/mollifier/items/6fdeff2750fe80f830c8
typeset -U fpath FPATH # 重複したパスを除外する
#typeset -x FPATH # 環境変数にexportする
# http://www.clear-code.com/blog/2011/9/5.html
# (N-/): 存在しないディレクトリは登録しない。
# パス(...): ...という条件にマッチするパスのみ残す。
# N: NULL_GLOBオプションを設定。
# globがマッチしなかったり存在しないパスを無視する。
# -: シンボリックリンク先のパスを評価。
# /: ディレクトリのみ残す。
# FPATHはサブシェルに引繼がれないので此處で設定する。
fpath=(
$ZDOTDIR/functions(N-/)
$fpath
)
# }}}
# {{{ RCFILES
autoload -Uz setup-rc && setup-rc
# }}}
# {{{ LSCOLORS
# ls (lscolors)
# DIR_COLORS, LS_COLORS
# http://journal.mycom.co.jp/column/zsh/009/index.html
case "$TERM" in
kterm*|xterm*|screen*)
local dircolorspath=$HOME/.dir_colors
if [[ -f ${dircolorspath} ]]; then
case "${OSTYPE}" in
darwin*)
# need 'brew install coreutils'
if [[ -x $(whence gdircolors) ]]; then
eval $(gdircolors ${dircolorspath})
fi
;;
*)
if [[ -x $(whence dircolors) ]]; then
eval $(dircolors ${dircolorspath})
fi
;;
esac
fi
if [[ -z $LSCOLORS ]]; then
LSCOLORS=exfxcxdxbxegedabagacad
zstyle ':completion:*' list-colors 'di=34' 'ln=35' 'so=32' 'ex=31' 'bd=46;34' 'cd=43;34'
fi
if [[ -z $LS_COLORS ]]; then
LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30'
zstyle ':completion:*' list-colors 'di=34' 'ln=35' 'so=32' 'ex=31' 'bd=46;34' 'cd=43;34'
fi
;;
cons25)
unset LANG
if [[ -z $LSCOLORS ]]; then
LSCOLORS=ExFxCxdxBxegedabagacad
zstyle ':completion:*' list-colors 'di=;34;1' 'ln=;35;1' 'so=;32;1' 'ex=31;1' 'bd=46;34' 'cd=43;34'
fi
if [[ -z $LS_COLORS ]]; then
LS_COLORS='di=01;34:ln=01;35:so=01;32:ex=01;31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30'
zstyle ':completion:*' list-colors 'di=;34;1' 'ln=;35;1' 'so=;32;1' 'ex=31;1' 'bd=46;34' 'cd=43;34'
fi
;;
esac
# }}}
# {{{ ディレクトリ移動関連 (chpwd)
setopt auto_cd # ディレクトリ名だけでcd
setopt auto_pushd # cdするたびにスタックに積む
setopt cdable_vars
setopt pushd_ignore_dups # 重複してスタックに積まない
mdcd(){mkdir -p "$@" && cd "$*[-1]"}
mdpu(){mkdir -p "$@" && pushd "$*[-1]"}
# cdコマンドに対する検索対象に$HOMEを追加。
cdpath=(
~
~/scm(N-/)
)
# cdの後でlsを実行
# http://qiita.com/yuyuchu3333/items/b10542db482c3ac8b059
autoload -Uz ls_after_cd && add-zsh-hook chpwd ls_after_cd
# 自動でhsenvをactivate/deactivate
# http://qiita.com/saturday06/items/3b67861b8ebcadeb01cd
autoload -Uz auto_hsenv && add-zsh-hook precmd auto_hsenv
# }}}
# {{{ history (履歴関連)
# `zsh` の `history` は `fc -l` のエイリアス (man zshbuiltins)
# http://qiita.com/syui/items/c1a1567b2b76051f50c4
# http://www.clear-code.com/blog/2011/9/5.html
#setopt hist_ignore_dups
#setopt hist_ignore_space
#setopt inc_append_history
setopt extended_history
setopt hist_ignore_all_dups
setopt hist_no_store
setopt hist_reduce_blanks
setopt hist_verify
setopt share_history
bindkey '^p' history-beginning-search-backward
bindkey '^n' history-beginning-search-forward
HISTFILE=$HOME/.zhistory
HISTSIZE=1000000
SAVEHIST=1000000
# 陳腐な履歴は殘さず。
# http://d.hatena.ne.jp/UDONCHAN/20100618/1276842846
# 失敗したコマンドは履歴に残したくないが、下記の記事を読むと無理そう。
# http://qiita.com/mollifier/items/558712f1a93ee07e22e2
add-my-history() {
unsetopt sh_word_split # sh_word_splitが有効だとエラーになる。
local line=${1%%$'\n'}
local cmd=${line%% *}
[[ ${cmd} != (cd|exit|history|kill|l|l[asl]|rm|sudo|/) ]]
}
add-zsh-hook zshaddhistory add-my-history
# `peco` と連携。
# http://qiita.com/shepabashi/items/f2bc2be37a31df49bca5
if [[ -x $(whence peco) ]]; then
peco-history-selection() {
BUFFER=$(fc -lnr 1 | awk '!a[$0]++' | peco)
CURSOR=$#BUFFER
zle reset-prompt
}
zle -N peco-history-selection
bindkey '^R' peco-history-selection
fi
# }}}
# {{{ エイリアス關聯 (alias)
# http://www.clear-code.com/blog/2011/9/5.html
alias copy='cp -ip'
alias del='rm -i'
alias dirs='dirs -v'
alias fullreset='echo "\ec\ec"'
alias ja='LANG=ja_JP.eucJP XMODIFIERS=@im=kinput2'
alias la='ls -a'
alias ll='ls -la'
alias move='mv -i'
alias po='popd'
alias pu='pushd'
# lvがなくてもlvでページャーを起動する。
if [[ -n $PAGER && $PAGER != "lv" ]]; then
alias lv=$PAGER
fi
# Alias and functions
case "$OSTYPE" in
freebsd*|darwin*)
alias man='env -u LANG man'
if [[ -x $(whence gls) ]]; then
alias ls='gls -F --color=auto'
else
alias ls='ls -F -G -w'
fi
;;
*)
alias man='env --unset LANG man'
alias ls='ls -F --color=auto'
;;
esac
# Suffix aliases(起動コマンドは環境によって変更する)
alias -s pdf=acroread dvi=xdvi
alias -s {odt,ods,odp,doc,xls,ppt}=soffice
alias -s {tgz,lzh,zip,arc}=file-roller
# }}}
autoload -Uz setup-widgets && setup-widgets
autoload -Uz setup-direnv && setup-direnv
autoload -Uz setup-git && setup-git
autoload -Uz setup-go && setup-go
autoload -Uz setup-less && setup-less
autoload -Uz setup-ndenv && setup-ndenv
autoload -Uz setup-stack && setup-stack
autoload -Uz 256colortest
autoload -Uz man
autoload -Uz tm
autoload -Uz zman
# {{{ プロンプト関連 (prompt)
# http://blog.8-p.info/2009/01/red-prompt
# http://d.hatena.ne.jp/kakurasan/20100407/p1
# http://kitak.hatenablog.jp/entry/2013/05/25/103059
# http://less.carbonfairy.org/post/17714419750
# http://usami-k.seesaa.net/article/253493442.html
# http://www.clear-code.com/blog/2011/9/5.html
# http://www.slideshare.net/tetutaro/zsh-20923001
setopt always_last_prompt # 補完のときプロンプトの位置を変えない
setopt prompt_subst # プロンプトでエスケープシーケンスを有効に
setopt transient_rprompt # コマンド実行rprompt消去
autoload -Uz colors && colors # プロンプトのカラー表示を有効
# VCS
autoload -Uz vcs_info
zstyle ':vcs_info:*' formats '(%s/%b)'
zstyle ':vcs_info:*' actionformats '(%s/%b|%a)'
# commitしていない変更をチェックする
zstyle ":vcs_info:git:*" check-for-changes true
# gitリポジトリに対して、変更情報とリポジトリ情報を表示する
zstyle ":vcs_info:git:*" formats "%s/%b%c%u"
# gitリポジトリに対して、コンフリクトなどの情報を表示する
zstyle ":vcs_info:git:*" actionformats "%s/%b:%a%c%u"
# addしていない変更があることを示す文字列
zstyle ":vcs_info:git:*" unstagedstr ":U"
# commitしていないstageがあることを示す文字列
zstyle ":vcs_info:git:*" stagedstr ":S"
autoload -Uz prompt_with_git && add-zsh-hook precmd prompt_with_git
case "$UID" in
0)
PROMPT='%B%m{%n}%%%b '
RPROMPT='%B[%~]%b'
PATH=/bin:/sbin:/usr/bin:/usr/sbin
;;
*)
# 直前のコマンドが失敗時にステータスを表示
local _exitst=$'%(?..%F{red}(%0?%) %f)'
local _prompt=$'%F{yellow}%n%f%F{green}@%m%f ${_exitst}%# '
# psvar[1]が存在すれば緑色で表示 (See `man zshmics')
local _vcs=$'%1(v.%F{green}%1v%f.)'
local _cwd=$'%F{cyan}[%~]%f'
local _rprompt='${_vcs}${_cwd}'
local _lf=$'\n'
# ディレクトリに三階層目が存在すれば
# ${_rprompt}と${_lf}を表示
PROMPT="%3(~.${_rprompt}${_lf}.)${_prompt}"
# ディレクトリに三階層目が存在しなければ
# ${_rpromt}を表示
RPROMPT="%3(~..${_rprompt})"
;;
esac
# }}}
if [[ $SHELL =~ "/zsh$" ]]; then
restart-zsh () {
echo "restart $SHELL"
exec $SHELL -l
}
fi
debug_echo "(end) .zshrc"
# vim: expandtab filetype=zsh foldmethod=marker shiftwidth=4 softtabstop=4 ts=4