-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.zshrc
More file actions
342 lines (277 loc) · 10.2 KB
/
.zshrc
File metadata and controls
342 lines (277 loc) · 10.2 KB
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
# ==========================
# general settings
# =========================
# 文字コードの指定
export LANG=ja_JP.UTF-8
# ヒストリの設定
HISTFILE=~/.zsh_history
HISTSIZE=1000000
SAVEHIST=1000000
# スペースから始まるコマンドはヒストリに残さない
setopt hist_ignore_space
# ビープ音を停止する
setopt nolistbeep
# cd -<tab>で以前移動したディレクトリを表示
setopt auto_pushd
# 直前と同じコマンドの場合は履歴に追加しない
setopt hist_ignore_dups
# 同じコマンドをヒストリに残さない
setopt hist_ignore_all_dups
# ビープ音の停止
setopt no_beep
# 同時に起動したzshの間でヒストリを共有する
setopt share_history
# 日本語ファイル名を表示可能にする
setopt print_eight_bit
# 色を使用出来るようにする
autoload -Uz colors
# ヒストリに保存するときに余分なスペースを削除する
setopt hist_reduce_blanks
set ehist_reduce_blankxpandtab
set tabstop=2
set shiftwidth=2
# Less の文字コードを UTF-8 に設定する
export LESSCHARSET=utf-8
# rootは履歴を残さない
if [ $UID = 0 ]; then
unset HISTFILE
SAVEHIST=0
fi
type nvim > /dev/null 2>&1
if [ $? -eq 0 ] ; then
export GIT_EDITOR=vim
alias vim='nvim'
fi
# ==========================
# completion settings
# =========================
# zsh-completions で補完機能を強化する
fpath=(/usr/local/share/zsh-completions/src $fpath)
autoload -U compinit
compinit -u
# 候補が多い場合は詰めて表示
setopt list_packed
# コマンドラインの引数でも補完を有効にする(--prefix=/userなど)
setopt magic_equal_subst
# コマンドのスペルミスを指摘
setopt correct
## ディレクトリ名の補完で末尾の / を自動的に付加し、次の補完に備える
setopt auto_param_slash
# sudo の後ろでコマンド名を補完する
zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin \
/usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin
# ps コマンドのプロセス名補完
zstyle ':completion:*:processes' command 'ps x -o pid,s,args'
## 補完候補のカーソル選択を有効に
zstyle ':completion:*:default' menu select=1
# ==========================
# path settings
# =========================
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:~/.npm-global/bin:$PATH"
# nodebrew のパス設定
export PATH="$HOME/.nodebrew/current/bin:$PATH"
# rbenv のパス設定
export PATH="$HOME/.rbenv/bin:$PATH"
# heroku toolbelt のパス設定
export PATH="/usr/local/heroku/bin:$PATH"
# pyenv のパス設定
export PYENV_ROOT="${HOME}/.pyenv"
export PATH="${PYENV_ROOT}/bin:${PATH}"
# postgresql のパス設定
export PATH="/usr/local/opt/postgresql@9.6/bin:${PATH}"
# go のパス設定
export GOPATH=~/go
export PATH=$GOPATH/bin:$PATH
# avr-gcc のパス設定
export PATH="/usr/local/opt/avr-gcc@7/bin:$PATH"
# ==========================
# vcs_info settings
# http://qiita.com/mollifier/items/8d5a627d773758dd8078
# =========================
RPROMPT=""
autoload -Uz vcs_info
autoload -Uz add-zsh-hook
autoload -Uz is-at-least
# 以下の3つのメッセージをエクスポートする
# $vcs_info_msg_0_ : 通常メッセージ用 (緑)
# $vcs_info_msg_1_ : 警告メッセージ用 (黄色)
# $vcs_info_msg_2_ : エラーメッセージ用 (赤)
zstyle ':vcs_info:*' max-exports 3
zstyle ':vcs_info:*' enable git svn hg bzr
# 標準のフォーマット(git 以外で使用)
# misc(%m) は通常は空文字列に置き換えられる
zstyle ':vcs_info:*' formats '(%s)-[%b]'
zstyle ':vcs_info:*' actionformats '(%s)-[%b]' '%m' '<!%a>'
zstyle ':vcs_info:(svn|bzr):*' branchformat '%b:r%r'
zstyle ':vcs_info:bzr:*' use-simple true
if is-at-least 4.3.10; then
# git 用のフォーマット
# git のときはステージしているかどうかを表示
zstyle ':vcs_info:git:*' formats '(%s)-[%b]' '%c%u %m'
zstyle ':vcs_info:git:*' actionformats '(%s)-[%b]' '%c%u %m' '<!%a>'
zstyle ':vcs_info:git:*' check-for-changes true
zstyle ':vcs_info:git:*' stagedstr "+" # %c で表示する文字列
zstyle ':vcs_info:git:*' unstagedstr "-" # %u で表示する文字列
fi
# hooks 設定
if is-at-least 4.3.11; then
# git のときはフック関数を設定する
# formats '(%s)-[%b]' '%c%u %m' , actionformats '(%s)-[%b]' '%c%u %m' '<!%a>'
# のメッセージを設定する直前のフック関数
# 今回の設定の場合はformat の時は2つ, actionformats の時は3つメッセージがあるので
# 各関数が最大3回呼び出される。
zstyle ':vcs_info:git+set-message:*' hooks \
git-hook-begin \
git-untracked \
git-push-status \
git-nomerge-branch \
git-stash-count
# フックの最初の関数
# git の作業コピーのあるディレクトリのみフック関数を呼び出すようにする
# (.git ディレクトリ内にいるときは呼び出さない)
# .git ディレクトリ内では git status --porcelain などがエラーになるため
function +vi-git-hook-begin() {
if [[ $(command git rev-parse --is-inside-work-tree 2> /dev/null) != 'true' ]]; then
# 0以外を返すとそれ以降のフック関数は呼び出されない
return 1
fi
return 0
}
# untracked ファイル表示
#
# untracked ファイル(バージョン管理されていないファイル)がある場合は
# unstaged (%u) に ? を表示
function +vi-git-untracked() {
# zstyle formats, actionformats の2番目のメッセージのみ対象にする
if [[ "$1" != "1" ]]; then
return 0
fi
if command git status --porcelain 2> /dev/null \
| awk '{print $1}' \
| command grep -F '??' > /dev/null 2>&1 ; then
# unstaged (%u) に追加
hook_com[unstaged]+='?'
fi
}
# push していないコミットの件数表示
#
# リモートリポジトリに push していないコミットの件数を
# pN という形式で misc (%m) に表示する
function +vi-git-push-status() {
# zstyle formats, actionformats の2番目のメッセージのみ対象にする
if [[ "$1" != "1" ]]; then
return 0
fi
if [[ "${hook_com[branch]}" != "master" ]]; then
# master ブランチでない場合は何もしない
return 0
fi
# push していないコミット数を取得する
local ahead
ahead=$(command git rev-list origin/master..master 2>/dev/null \
| wc -l \
| tr -d ' ')
if [[ "$ahead" -gt 0 ]]; then
# misc (%m) に追加
hook_com[misc]+="(p${ahead})"
fi
}
# マージしていない件数表示
#
# master 以外のブランチにいる場合に、
# 現在のブランチ上でまだ master にマージしていないコミットの件数を
# (mN) という形式で misc (%m) に表示
function +vi-git-nomerge-branch() {
# zstyle formats, actionformats の2番目のメッセージのみ対象にする
if [[ "$1" != "1" ]]; then
return 0
fi
if [[ "${hook_com[branch]}" == "master" ]]; then
# master ブランチの場合は何もしない
return 0
fi
local nomerged
nomerged=$(command git rev-list master..${hook_com[branch]} 2>/dev/null | wc -l | tr -d ' ')
if [[ "$nomerged" -gt 0 ]] ; then
# misc (%m) に追加
hook_com[misc]+="(m${nomerged})"
fi
}
# stash 件数表示
#
# stash している場合は :SN という形式で misc (%m) に表示
function +vi-git-stash-count() {
# zstyle formats, actionformats の2番目のメッセージのみ対象にする
if [[ "$1" != "1" ]]; then
return 0
fi
local stash
stash=$(command git stash list 2>/dev/null | wc -l | tr -d ' ')
if [[ "${stash}" -gt 0 ]]; then
# misc (%m) に追加
hook_com[misc]+=":S${stash}"
fi
}
fi
function _update_vcs_info_msg() {
local -a messages
local prompt
LANG=en_US.UTF-8 vcs_info
if [[ -z ${vcs_info_msg_0_} ]]; then
# vcs_info で何も取得していない場合はプロンプトを表示しない
prompt=""
else
# vcs_info で情報を取得した場合
# $vcs_info_msg_0_ , $vcs_info_msg_1_ , $vcs_info_msg_2_ を
# それぞれ緑、黄色、赤で表示する
[[ -n "$vcs_info_msg_0_" ]] && messages+=( "%F{green}${vcs_info_msg_0_}%f" )
[[ -n "$vcs_info_msg_1_" ]] && messages+=( "%F{yellow}${vcs_info_msg_1_}%f" )
[[ -n "$vcs_info_msg_2_" ]] && messages+=( "%F{red}${vcs_info_msg_2_}%f" )
# 間にスペースを入れて連結する
prompt="${(j: :)messages}"
fi
RPROMPT="$prompt"
}
add-zsh-hook precmd _update_vcs_info_msg
# ==========================
# rbenv settings
# =========================
if command -v rbenv 1>/dev/null 2>&1; then eval "$(rbenv init -)"; fi
# ==========================
# pyenv settings
# =========================
if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)"; fi
# =========================
# virtualenv settings
# =======================
if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv virtualenv-init -)"; fi
# =========================
# tmux settings
# =======================
type tmux > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
# get the IDs
ID="`tmux list-sessions`"
if [[ -z "$ID" ]]; then
tmux new-session
fi
ID="`echo $ID | $PERCOL | cut -d: -f1`"
tmux attach-session -t "$ID"
fi
# =========================
# nvm settings
#
# https://github.com/nvm-sh/nvm#installing-and-updating
# =======================
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# =========================
# fzf settings
#
# https://github.com/junegunn/fzf#installation
# =======================
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# =========================
# PROMPT settings
# =======================
PROMPT=$'%F{green}[%f %~ %F{green}]%f → '