-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
268 lines (211 loc) · 6.69 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
# -------------------------------------
# zplug
# -------------------------------------
export ZPLUG_HOME=$HOME/.zplug
source $ZPLUG_HOME/init.zsh
#compile if .zwc is old
if [ ~/.zshrc -nt ~/.zshrc.zwc ]; then
echo "zcompile .zshrc"
zcompile ~/.zshrc
fi
if [ ~/.zshenv -nt ~/.zshenv.zwc ]; then
echo "zcompile .zshenv"
zcompile ~/.zshenv
fi
zplug "zplug/zplug", hook-build:"zplug --self-manage"
zplug "zsh-users/zsh-syntax-highlighting", defer:2
zplug "zsh-users/zsh-completions"
zplug "zsh-users/zsh-autosuggestions", defer:2
zplug "b4b4r07/enhancd", use:init.sh
# zplug "themes/candy-modified", from:oh-my-zsh, as:theme
zplug "themes/candy", from:oh-my-zsh, as:theme
# Install plugins if there are plugins that have not been installed
if ! zplug check --verbose; then
printf "Install(zplug)? [y/N]: "
if read -q; then
echo; zplug install
fi
fi
zplug load
# -------------------------------------
# Path
# -------------------------------------
export DEFAULT_USER="shu"
# 重複する要素を自動的に削除
typeset -U path cdpath fpath manpath
export PATH="$HOME/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:$HOME/.local/bin"
. /opt/homebrew/opt/asdf/asdf.sh
export GOENV_DISABLE_GOPATH=1
export XDG_CONFIG_HOME=$HOME/dotfiles
eval "$(/opt/homebrew/bin/brew shellenv)"
export JAVA_OPTS='-Dfile.encoding=UTF-8'
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export FZF_DEFAULT_OPTS="--ansi --select-1 --exit-0 --multi --reverse"
export GOPATH=$HOME
export GOBIN=$GOPATH/bin
# -------------------------------------
# Environment Variables
# -------------------------------------
export LANG=en_US.UTF-8
# -------------------------------------
# zsh options
# -------------------------------------
set -o emacs
export 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=32' 'ex=31'
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*:default' menu select=2
## 補完機能の強化
autoload -U compinit
compinit
## 入力しているコマンド名が間違っている場合にもしかして:を出す。
setopt correct
# ビープを鳴らさない
setopt nobeep
## ^Dでログアウトしない。
setopt ignoreeof
## バックグラウンドジョブが終了したらすぐに知らせる。
setopt notify
## タブによるファイルの順番切り替えをする
setopt auto_menu
## ディレクトリ名を入力するだけでcdできるようにする
setopt auto_cd
## Command history configuration
HISTFILE=${HOME}/.zsh_history
HISTSIZE=200000
SAVEHIST=200000
setopt hist_ignore_dups # ignore duplication command history list
setopt share_history # share command history data
# -------------------------------------
# Alias
# -------------------------------------
# exit
alias q="exit"
if [[ -x `which lsd` ]]; then
alias ls="lsd"
fi
# ls color
case "${OSTYPE}" in
darwin*)
alias la="ls -a"
alias ll="ls -l"
alias lla="ls -la"
alias lt="ls --tree"
;;
linux*)
alias la='ls -a --color'
alias ll='ls -l --color'
alias lla='ls -la --color'
alias lt='ls --tree --color'
;;
esac
alias lsg="ls | grep "
# if [[ -x `which diff-so-fancy` ]]; then
# alias diff='diff-so-fancy'
# else
# alias diff='diff -u'
# fi
# vim
alias vi="nvim"
alias vim="nvim"
alias vimdiff="nvim -d"
# Terraform
alias tf="terraform"
# BSD -> GNU commands
if [[ -x `which gxargs` ]]; then
alias xargs='gxargs'
fi
if [[ -x `which gdate` ]]; then
alias date='gdate'
fi
if [[ -x `which gsed` ]]; then
alias sed='gsed'
fi
if [[ -x `which gseq` ]]; then
alias seq='gseq'
fi
if [[ -x `which gtar` ]]; then
alias tar='gtar'
fi
# Docker for Mac VM への ssh
alias docker-ssh='docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i bash'
# reset docker world
alias docker-balus='docker system prune -af --volumes && docker rmi $(docker images -a -q)'
# postgresql起動
alias psqlstart="postgres -D /usr/local/var/postgres"
# コンフィグ編集
alias zshconf="vim ~/.zshrc"
alias zshmine="vim ~/.zshrc.mine"
alias vimconf="vim ~/dotfiles/nvim"
alias sshconf="vim ~/.ssh/config"
# -n 行数表示, -I バイナリファイル無視, svn関係のファイルを無視
alias grep="grep --color -n -I --exclude='*.svn-*' --exclude='entries' --exclude='*/cache/*'"
# Git
# 個別のエイリアスは.gitconfignに記載
alias g="git"
alias hb='hub browse $(ghq list | fzf | cut -d "/" -f 2,3)'
# -------------------------------------
# Key Binds
# -------------------------------------
# historical backward/forward search with linehead string binded to ^P/^N
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
bindkey "\\ep" history-beginning-search-backward-end
bindkey "\\en" history-beginning-search-forward-end
# zshで特定のコマンドをヒストリに追加しない条件を柔軟に設定する - mollifier delta blog
# http://mollifier.hatenablog.com/entry/20090728/p1
zshaddhistory() {
local line=${1%%$'\n'}
local cmd=${line%% *}
# 以下の条件をすべて満たすものだけをヒストリに追加する
[[ ${#line} -ge 4
&& ${cmd} != (m|man)
]]
}
# http://d.hatena.ne.jp/kbkbkbkb1/20120429/1335835500
# をfzfに変更
function select_history() {
# export LC_CTYPE=C
# local tac_cmd
# which gtac &> /dev/null && tac_cmd=gtac || tac_cmd=tac
# BUFFER=$($tac_cmd ~/.zsh_history | sed 's/^: [0-9]*:[0-9]*;//' \
# | fzf --query "$LBUFFER")
# CURSOR=$#BUFFER # move cursor
# zle -R -c # refresh
# export LC_CTYPE=ja_JP.UTF-8
local tac=${commands[tac]:-"tail -r"}
BUFFER=$( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | sed 's/ *[0-9]* *//' | eval $tac | awk '!a[$0]++' | fzf +s)
CURSOR=$#BUFFER
zle clear-screen
}
zle -N select_history
bindkey '^R' select_history
function peco_src() {
local src_dir=$(ghq list --full-path | fzf --query "$LBUFFER")
if [ -n "$src_dir" ]; then
BUFFER="cd $src_dir"
zle accept-line
fi
# zle clean-screen
zle -R -c # refresh
}
zle -N peco_src
# bindkey '^S' peco_srcがなぜか効かないので
bindkey '^]' peco_src
# -------------------------------------
# Others
# -------------------------------------
function avt {
profile=$1; shift
aws-vault exec $profile -- "$@";
}
# "ls" after "cd" automatically
function chpwd() { ls }
# enable git-extras aliases
source /opt/homebrew/opt/git-extras/share/git-extras/git-extras-completion.zsh
# read environment specific settings
source ~/.zshrc.mine
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh