-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
375 lines (288 loc) · 9.22 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
#
# Executes commands at the start of an interactive session.
#
# Created by newuser for 5.4.2
# -----------------------------
# Lang
# -----------------------------
#export LANG=ja_JP.UTF-8
#export LESSCHARSET=utf-8
# -----------------------------
# General
# -----------------------------
# 色を使用
autoload -Uz colors ; colors
# エディタをvimに設定
export EDITOR=vim
# Ctrl+Dでログアウトしてしまうことを防ぐ
#setopt IGNOREEOF
# パスを追加したい場合
export PATH="$HOME/bin:$PATH"
# cdした際のディレクトリをディレクトリスタックへ自動追加
setopt auto_pushd
# ディレクトリスタックへの追加の際に重複させない
setopt pushd_ignore_dups
# emacsキーバインド
bindkey -e
# viキーバインド
#bindkey -v
# フローコントロールを無効にする
setopt no_flow_control
# ワイルドカード展開を使用する
setopt extended_glob
# cdコマンドを省略して、ディレクトリ名のみの入力で移動
setopt auto_cd
# コマンドラインがどのように展開され実行されたかを表示するようになる
#setopt xtrace
# 自動でpushdを実行
setopt auto_pushd
# pushdから重複を削除
setopt pushd_ignore_dups
# ビープ音を鳴らさないようにする
setopt no_beep
# カッコの対応などを自動的に補完する
setopt auto_param_keys
# ディレクトリ名の入力のみで移動する
setopt auto_cd
# bgプロセスの状態変化を即時に知らせる
setopt notify
# 8bit文字を有効にする
setopt print_eight_bit
# 終了ステータスが0以外の場合にステータスを表示する
setopt print_exit_value
# ファイル名の展開でディレクトリにマッチした場合 末尾に / を付加
setopt mark_dirs
# コマンドのスペルチェックをする
setopt correct
# コマンドライン全てのスペルチェックをする
setopt correct_all
# 上書きリダイレクトの禁止
setopt no_clobber
# 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'
# パスの最後のスラッシュを削除しない
setopt noautoremoveslash
# 各コマンドが実行されるときにパスをハッシュに入れる
#setopt hash_cmds
# rsysncでsshを使用する
export RSYNC_RSH=ssh
# その他
umask 022
ulimit -c 0
# -----------------------------
# Prompt
# -----------------------------
# %M ホスト名
# %m ホスト名
# %d カレントディレクトリ(フルパス)
# %~ カレントディレクトリ(フルパス2)
# %C カレントディレクトリ(相対パス)
# %c カレントディレクトリ(相対パス)
# %n ユーザ名
# %# ユーザ種別
# %? 直前のコマンドの戻り値
# %D 日付(yy-mm-dd)
# %W 日付(yy/mm/dd)
# %w 日付(day dd)
# %* 時間(hh:flag_mm:ss)
# %T 時間(hh:mm)
# %t 時間(hh:mm(am/pm))
#PROMPT='%F{cyan}%n@%m%f:%~# '
autoload -Uz vcs_info
setopt prompt_subst
zstyle ':vcs_info:*' formats "%F{green}[%r@%b][%S]"
zstyle ':vcs_info:*' actionformats '[%b|%a]'
precmd () { vcs_info }
RPROMPT=$RPROMPT'${vcs_info_msg_0_}'
PROMPT="
%{%D:%*${fg[yellow]}%} %~%{${reset_color}%}
%F{cyan}%n@%m# "
# -----------------------------
# Completion
# -----------------------------
# 自動補完を有効にする
autoload -Uz compinit ; compinit
# 単語の入力途中でもTab補完を有効化
setopt complete_in_word
# コマンドミスを修正
setopt correct
# 補完の選択を楽にする
zstyle ':completion:*' menu select
# 補完候補をできるだけ詰めて表示する
setopt list_packed
# 補完候補にファイルの種類も表示する
#setopt list_types
# 色の設定
export LSCOLORS=Exfxcxdxbxegedabagacad
# 補完時の色設定
export 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::complete:*' use-cache true
# 補完候補に色つける
autoload -U colors ; colors ; zstyle ':completion:*' list-colors "${LS_COLORS}"
#zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# 大文字・小文字を区別しない(大文字を入力した場合は区別する)
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# manの補完をセクション番号別に表示させる
zstyle ':completion:*:manuals' separate-sections true
# --prefix=/usr などの = 以降でも補完
setopt magic_equal_subst
# -----------------------------
# History
# -----------------------------
# 基本設定
HISTFILE=$HOME/.zsh-history
HISTSIZE=100000
SAVEHIST=1000000
# ヒストリーに重複を表示しない
setopt histignorealldups
# 他のターミナルとヒストリーを共有
setopt share_history
# すでにhistoryにあるコマンドは残さない
setopt hist_ignore_all_dups
# historyに日付を表示
alias h='fc -lt '%F %T' 1'
# ヒストリに保存するときに余分なスペースを削除する
setopt hist_reduce_blanks
# 履歴をすぐに追加する
setopt inc_append_history
# ヒストリを呼び出してから実行する間に一旦編集できる状態になる
setopt hist_verify
#余分なスペースを削除してヒストリに記録する
#setopt hist_reduce_blanks
# historyコマンドは残さない
#setopt hist_save_no_dups
# ^R で履歴検索をするときに * でワイルドカードを使用出来るようにする
#bindkey '^R' history-incremental-pattern-search-backward
#bindkey "^S" history-incremental-search-forward
# ^P,^Nを検索へ割り当て
#bindkey "^P" history-beginning-search-backward-end
#bindkey "^N" history-beginning-search-forward-end
# -----------------------------
# Alias
# -----------------------------
# グローバルエイリアス
alias -g L='| less'
alias -g H='| head'
alias -g G='| grep'
alias -g GI='| grep -ri'
# エイリアス
alias lst='ls -ltr --color=auto'
alias ls='ls --color=auto'
alias la='ls -la --color=auto'
alias ll='ls -l --color=auto'
alias du="du -Th"
alias df="df -Th"
alias ovim="vim"
alias vim="nvim"
alias su="su -l"
alias so='source'
alias vi='vim'
alias vz='vim ~/.zshrc'
alias c='cdr'
alias cp='cp -i'
alias rm='rm -i'
alias mkdir='mkdir -p'
alias ..='c ../'
alias back='pushd'
alias diff='diff -U1'
alias tma='tmux attach'
alias tml='tmux list-window'
alias dki="docker run -i -t -P"
alias dex="docker exec -i -t"
alias drmf='docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)'
# -----------------------------
# Plugin
# -----------------------------
# root のコマンドはヒストリに追加しない
#if [ $UID = 0 ]; then
# unset HISTFILE
# SAVEHIST=0
#fi
#function h {
# history
#}
#function g() {
# egrep -r "$1" .
#}
function t()
{
tmux new-session -s $(pwd |sed -E 's!^.+/([^/]+/[^/]+)$!\1!g' | sed -e 's/\./-/g')
}
function psgrep() {
ps aux | grep -v grep | grep "USER.*COMMAND"
ps aux | grep -v grep | grep $1
}
function dstop()
{
docker stop $(docker ps -a -q);
}
function drm()
{
docker rm $(docker ps -a -q);
}
# -----------------------------
# Plugin
# -----------------------------
# zplugが無ければインストール
if [[ ! -d ~/.zplug ]];then
git clone https://github.com/zplug/zplug ~/.zplug
fi
# zplugを有効化する
source ~/.zplug/init.zsh
# プラグインList
# zplug "ユーザー名/リポジトリ名", タグ
zplug "zsh-users/zsh-completions"
zplug "zsh-users/zsh-autosuggestions"
# コマンドを種類ごとに色付け
zplug "zsh-users/zsh-syntax-highlighting", defer:2
# ヒストリの補完を強化する
zplug "zsh-users/zsh-history-substring-search", defer:3
# git の補完を効かせる
# 補完&エイリアスが追加される
zplug "plugins/git", from:oh-my-zsh
zplug "peterhurford/git-aliases.zsh"
# 非同期処理
zplug "mafredri/zsh-async"
# 本体(連携前提のパーツ)
zplug "junegunn/fzf", as:command, use:bin/fzf-tmux
# fzf でよく使う関数の詰め合わせ
zplug "mollifier/anyframe"
# ディレクトリ移動を高速化(fzf であいまい検索)
zplug "b4b4r07/enhancd", use:init.sh
# git のローカルリポジトリを一括管理(fzf でリポジトリへジャンプ)
# zplug "motemen/ghq", as:command, from:gh-r
# インストールしていないプラグインをインストール
if ! zplug check --verbose; then
printf "Install? [y/N]: "
if read -q; then
echo; zplug install
fi
fi
# コマンドをリンクして、PATH に追加し、プラグインは読み込む
zplug load
# -----------------------------
# PATH
# -----------------------------
case "${OSTYPE}" in
darwin*)
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:/opt/local/man:$MANPATH
;;
esac
# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
fvim() {
files=$(git ls-files) &&
selected_files=$(echo "$files" | fzf -m --preview 'head -100 {}') &&
vim $selected_files
}
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh