-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.zshrc
314 lines (273 loc) · 7.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
# _________________________________
#< Life is like a box of chocolate >
# ---------------------------------
# \ ^__^
# \ (oo)\_______
# (__)\ )\/\
# ||----w |
# || ||
# for debug
#zmodload zsh/zprof && zprof
# zplug init
if [[ ! -d ~/.zplug ]]; then
git clone https://github.com/zplug/zplug ~/.zplug
source ~/.zplug/init.zsh && zplug update --self
fi
source ~/.zplug/init.zsh
# bindkey
bindkey -e
# LANG
export LANG=ja_JP.UTF-8
# Use vim
export EDITOR="vim"
# set term env
export TERM="xterm-256color"
# PATH
# localのpipディレクトリにPATHを通す
export PATH=$HOME/.local/bin:$PATH
# Add zplug bin
export PATH=$HOME/.zplug/bin:$PATH
# Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
# for PyCharm shell integration
export PATH="$PATH:/usr/local/bin"
export PATH=$HOME/bin:$PATH
# go
export GOPATH=$HOME/.go
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:/usr/local/opt/go/libexec/bin
# poetry
export PATH=$PATH:$HOME/.poetry/bin
## サーバ個別のPATH設定をインポート
if [ -f ~/.zshrc.path ]; then
source ~/.zshrc.path
fi
# direnv
if type direnv >/dev/null 2>&1; then
eval "$(direnv hook zsh)"
fi
# エイリアス設定
alias vi="vim -u NONE --noplugin"
alias awk="gawk"
alias ll="ls -l"
alias la="ls -a"
alias mv="mv -i"
alias rm="rm -i"
alias grep="grep --color=auto -i"
alias zgrep="zgrep --color=auto -i"
alias egrep="egrep --color=auto -i"
alias src="source ~/.zshrc"
if type ccat > /dev/null 2>&1; then
alias cat="ccat"
fi
if type htop > /dev/null 2>&1; then
alias top="htop"
fi
## git 関係
alias gst="git status -sb"
alias gg="git status -sb"
alias gm="git commit -m"
alias gb="git branch -a"
alias co="git checkout"
## make
alias j4="echo-sd \"デマアアアァアァァシアアアアァァァアアア\!\!\!\!\"; make -j 4"
## グローバルエイリアス
alias -g L="| less"
alias -g G="| grep"
alias -g W="| wc"
## docker
alias dr="docker run --rm -it"
alias db="docker build"
## サーバ個別のalias設定をインポート
if [ -f ~/.zshrc.alias ]; then
source ~/.zshrc.alias
fi
## エスケープシーケンスカラーの設定
local DEFAULT=$'%{[m%}'
local RED=$'%{[1;31m%}'
local GREEN=$'%{[1;32m%}'
local YELLOW=$'%{[1;33m%}'
local BLUE=$'%{[1;34m%}'
local PURPLE=$'%{[1;35m%}'
local LIGHT_BLUE=$'%{[1;36m%}'
local WHITE=$'%{[1;37m%}'
# HISTORY
HISTFILE=~/.zsh_history
HISTSIZE=1000000
SAVEHIST=1000000
## history (fc -l) コマンドをヒストリリストから取り除く。
setopt hist_no_store
## すぐにヒストリファイルに追記する。
setopt inc_append_history
## 直前と同じコマンドをヒストリに追加しない
setopt hist_ignore_dups
## zsh の開始, 終了時刻をヒストリファイルに書き込む
setopt extended_history
## ヒストリを呼び出してから実行する間に一旦編集
setopt hist_verify
## ヒストリを共有
setopt share_history
## コマンドラインの先頭がスペースで始まる場合ヒストリに追加しない
setopt hist_ignore_space
# プロンプトの設定
# プロンプトが表示されるたびにプロンプト文字列を評価、置換する
setopt PROMPT_SUBST
# 補完
## 補完候補を一覧表示
setopt auto_list
## TAB で順に補完候補を切り替える
setopt auto_menu
## '='以降の入力も補完する
setopt magic_equal_subst
## 補完関数の設定
## 補完候補をカーソルで選択可能にする
zstyle ':completion:*:default' menu select=1
## 補完候補をグルーピングして表示する
zstyle ':completion:*' completer _expand _complete _match _approximate _history
# _expand: グロブや変数を展開する
# _complete: 通常の補完
# _match: グロブでコマンドを補完する
# _approximate: ミススペルを訂正して補完する
# _history: 履歴から補完する
zstyle ':completion:*:descriptions' format $YELLOW'completing %B%d%b'$DEFAULT
## 自動入力されるカンマなどを適宜削除する
setopt auto_param_keys
## 補完候補を詰めて表示
setopt list_packed
# others
## ビープを鳴らさない
setopt nobeep
## ディレクトリ名だけで cd
setopt auto_cd
## cdの履歴を保存
setopt auto_pushd
## 重複したcdの履歴は保存しない
setopt pushd_ignore_dups
## 3秒以上の処理は自動的に処理時間を表示
REPORTTIME=3
PURE_PROMPT_SYMBOL=">"
# pecoで履歴を検索する
function peco-history-selection() {
cmd='tac'
case "${OSTYPE}" in
freebsd*|darwin*)
cmd=('tail' '-r')
;;
esac
BUFFER=`history -n 1 | $cmd | awk '!a[$0]++' | peco`
CURSOR=$#BUFFER
zle reset-prompt
}
zle -N peco-history-selection
# pecoでスニペットを読み込む
function peco-snippets-loader() {
if ls ~/.peco.snippet* >/dev/null 2>&1; then
snippet=`cat ~/.peco.snippet* | grep -v "^#" | peco`
BUFFER="$(echo $snippet | sed -e 's/^\[.*\] *//') "
CURSOR=$#BUFFER
else
echo "~/.peco.snippet* is not found."
fi
zle reset-prompt
}
zle -N peco-snippets-loader
# peco ghq search
function peco-ghq-search() {
local selected_dir=$(ghq list -p | peco --query "$LBUFFER")
if [ -n "$selected_dir" ]; then
BUFFER="cd ${selected_dir}"
zle accept-line
fi
zle clear-screen
}
zle -N peco-ghq-search
# peco関係の関数をキーバインドに登録
if type peco >/dev/null 2>&1; then
bindkey '^r' peco-history-selection
bindkey '^]' peco-ghq-search
bindkey '^x' peco-snippets-loader
fi
function command_not_found_handler(){
if [ -e $HOME/bin/imgcat ];then
if [ -e ~/src/commandmiss/iori.jpg ];then
imgcat ~/src/commandmiss/iori.jpg
fi
fi
echo "ハァ…?$1とか何言ってんの?\nコマンドもろくに覚えられないなんて、アンタどうしようもないクズね。"
}
# tmux functions from: https://github.com/ssh0/dotfiles/blob/master/zshfiles/functions/tmux.zsh
TMUX_AUTO_START=true
tmux-new-session() {
if [[ -n $TMUX ]]; then
tmux switch-client -t "$(TMUX= tmux -S "${TMUX%,*,*}" new-session -dP "$@")"
else
tmux new-session "$@"
fi
}
tmux_sessions() {
# Select existing session or create session with fuzzy search tool
# get the IDs
if ! ID="$(tmux list-sessions 2>/dev/null)"; then
# tmux returned error, so try cleaning up /tmp
/bin/rm -rf /tmp/tmux*
fi
create_new_session="Create New Session"
if [[ -n "$ID" ]]; then
ID="${create_new_session}:\n$ID"
else
ID="${create_new_session}:"
fi
ID="$(echo $ID | peco | cut -d: -f1)"
if [[ "$ID" = "${create_new_session}" ]]; then
tmux-new-session
elif [[ -n "$ID" ]]; then
if [[ -n $TMUX ]]; then
tmux switch-client -t "$ID"
else
tmux attach-session -t "$ID"
fi
else
: # Start terminal normally
fi
}
if ${TMUX_AUTO_START:-false} && [[ ! -n $TMUX && $- == *l* ]]; then
tmux_sessions && exit
fi
# gitignore.io
function gi() {
curl -sL https://www.gitignore.io/api/$@
}
_gitignoreio_get_command_list() {
curl -sL https://www.gitignore.io/api/list | tr "," "\n"
}
_gitignoreio () {
compset -P '*,'
compadd -S '' `_gitignoreio_get_command_list`
}
compdef _gitignoreio gi
# zplug plugins
zplug 'mafredri/zsh-async', on:sindresorhus/pure
zplug 'sindresorhus/pure', use:pure.zsh, as:theme
zplug 'chrissicool/zsh-256color'
zplug "mrowa44/emojify", as:command
zplug 'b4b4r07/emoji-cli'
zplug 'zsh-users/zsh-completions'
zplug 'zsh-users/zsh-syntax-highlighting', defer:2
zplug 'yonchu/3935922', \
from:gist, \
as:plugin, \
use:'chpwd_for_zsh.sh'
zplug 'zplug/zplug', hook-build:'zplug --self-manage'
# Install plugins if there are plugins that have not been installed
if ! zplug check --verbose; then
printf "Install? [y/N]: "
if read -q; then
echo; zplug install
fi
fi
# Then, source plugins and add commands to $PATH
zplug load --verbose
# for debug
#if (which zprof > /dev/null) ;then
# zprof | less
#fi