-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
307 lines (240 loc) · 7.05 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
# ============================================================================ #
# zshrc #
# ============================================================================ #
# basic {{{
autoload -Uz add-zsh-hook
setopt extended_glob
setopt no_hup
setopt no_checkjobs
export EDITOR=vim
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LOCALE=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
bindkey -e
bindkey '^[[3~' delete-char
disable r
if [ "$TERM" != 'screen-256color' ]; then
export TERM='xterm-256color'
fi
# edit command in editor
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey '^xe' edit-command-line
export WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'
if [[ "${terminfo[kRIT]}" != "" ]]; then
bindkey "${terminfo[kRIT]}" forward-word
else
bindkey '^[[1;2C' forward-word
fi
if [[ "${terminfo[kLFT]}" != "" ]]; then
bindkey "${terminfo[kLFT]}" backward-word
else
bindkey '^[[1;2D' backward-word
fi
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'
# }}}
# OS dependent {{{
case "${OSTYPE}" in
darwin*)
alias ls='ls -GFv'
;;
linux-gnu*)
alias ls='ls --color -Fv'
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
alias open='xdg-open'
;;
esac
# }}}
# prompt {{{
# Git settings
# http://d.hatena.ne.jp/uasi/20091017/1255712789
# http://gist.github.com/214109
autoload -Uz VCS_INFO_get_data_git && VCS_INFO_get_data_git 2> /dev/null
setopt prompt_subst
function zshrc-prompt-git-info { # {{{
local branch st color gitdir action user stash
if [[ $(command git rev-parse --is-inside-work-tree 2> /dev/null) != 'true' ]]; then
return
fi
branch=$(basename "$(command git symbolic-ref HEAD 2> /dev/null)")
if [[ -z $branch ]]; then
branch=${"$(command git rev-parse HEAD 2> /dev/null)":0:7}
if [[ -z $branch ]]; then
branch='???????'
fi
fi
st=$(command git status 2> /dev/null)
if [[ -n $(echo "$st" | grep '^nothing to') ]]; then
color=green
elif [[ -n $(echo "$st" | grep '^no changes added') ]]; then
color=yellow
elif [[ -n $(echo "$st" | grep '^Changes to be committed') ]]; then
color=red
else
color=blue
fi
user=$(command git config --get user.name 2> /dev/null)
gitdir=$(command git rev-parse --git-dir 2> /dev/null)
action=$(VCS_INFO_git_getaction "$gitdir") && action="($action)"
stash=$(command git stash list 2>/dev/null | wc -l | tr -d ' ') && stash="[$stash]"
echo "%F{$color}$user$action@$branch$stash%f"
} # }}}
export PROMPT='%F{blue}[%D{%m/%d %H:%M:%S}]%f %F{cyan}%n@%m:%~%f $(zshrc-prompt-git-info)
%F{cyan}%(!.$.#)%f '
export RPROMPT=''
# }}}
# complete {{{
autoload -Uz compinit && compinit
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*' verbose true
zstyle ':completion:*:processes' command "ps -u $USER -o pid,command"
fpath=(
$HOME/Work/src/github.com/zsh-users/zsh-completions
/usr/local/share/zsh-completions
$fpath
)
fpath=(${^fpath}(N-/^W))
# }}}
# directory {{{
setopt auto_cd
setopt auto_pushd
setopt pushd_ignore_dups
alias ll='ls -l'
alias la='ls -al'
alias dir='ls'
function zshrc-chpwd() {
ls
}
add-zsh-hook chpwd zshrc-chpwd
hash -d me=$HOME/Work/src/github.com/scheakur
hash -d gh=$HOME/Work/src/github.com
hash -d tmp=$HOME/tmp
# }}}
# history {{{
export HISTFILE=~/.zsh_history
export HISTSIZE=1000000
export SAVEHIST=1000000
setopt append_history
setopt inc_append_history
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt extended_history
setopt share_history
setopt hist_reduce_blanks
setopt hist_no_store
setopt hist_no_functions
setopt interactive_comments
autoload -U 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 '^R' history-incremental-pattern-search-backward
bindkey '^S' history-incremental-pattern-search-forward
# }}}
# cdr {{{
# cdr
if [[ -n $(echo ${^fpath}/chpwd_recent_dirs(N)) && -n $(echo ${^fpath}/cdr(N)) ]]; then
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*' recent-dirs-insert both
zstyle ':chpwd:*' recent-dirs-default true
zstyle ':chpwd:*' recent-dirs-max 1000
zstyle ':chpwd:*' recent-dirs-file "$HOME/.cache/chpwd-recent-dirs"
fi
# }}}
# peco {{{
function zshrc-exists() {
which $1 &> /dev/null
}
function zshrc-peco-ghq-cd() {
local dir=$(ghq list --full-path | peco --query "$LBUFFER")
if [ -n "$dir" ]; then
BUFFER="cd ${dir}"
zle accept-line
fi
zle clear-screen
}
function zshrc-peco-mysnippets() {
local f=~/.config/peco/mysnippets.sh
BUFFER=$(cat $f | \grep -v '^#' | \grep -v '^$'| peco --query "$LBUFFER")
zle clear-screen
}
function zshrc-peco-history() {
BUFFER=`history -n 1 | tac | peco`
CURSOR=$#BUFFER
zle reset-prompt
}
function zshrc-peco-cdr () {
local dir=$(cdr -l | awk '{print $2}' | peco --query "$LBUFFER")
if [ -n "$dir" ]; then
BUFFER="cd ${dir}"
zle accept-line
fi
}
if zshrc-exists peco; then
if zshrc-exists ghq; then
zle -N zshrc-peco-ghq-cd
bindkey '^ ' zshrc-peco-ghq-cd
fi
zle -N zshrc-peco-mysnippets
bindkey '^x^s' zshrc-peco-mysnippets
zle -N zshrc-peco-history
bindkey '^r' zshrc-peco-history
zle -N zshrc-peco-cdr
bindkey '^n' zshrc-peco-cdr
fi
# }}}
# misc {{{
# enable alias in sudo
alias sudo='sudo '
alias grep='grep -Ein --color=auto'
export GREP_COLORS='fn=01;34:mt=00;33'
autoload -Uz zmv
alias zmv='noglob zmv -W -n'
alias zmv!='noglob zmv -W'
# vim -(^z)-> terminal -(^z)-> vim
bindkey -s '^z' '^[q fg^m'
alias v=vim
alias g=git
alias dc=docker-compose
function git() {
if [[ $1 == "clone" ]]; then
shift
ghq get $@
else
command git $@
fi
}
function mygit() {
url=$(command git remote get-url origin)
if [[ $url =~ ^https://github.com/scheakur/.* ]]; then
new_url='https://scheakur@'${url:8}
command git remote set-url origin $new_url
fi
}
alias hexdump='od -A x -t x1z -v'
alias ~~='cd $HOME/Work/src/github.com/scheakur'
alias tree='tree --charset ascii'
# }}}
# others {{{
[[ -f $HOME/.config/tmuxinator/tmuxinator.zsh ]] && source $HOME/.config/tmuxinator/tmuxinator.zsh
[[ -f $HOME/.pythonbrew/etc/bashrc ]] && source $HOME/.pythonbrew/etc/bashrc
[[ -f /usr/local/share/zsh/site-functions/_awless ]] && source /usr/local/share/zsh/site-functions/_awless
[[ -f /usr/local/bin/direnv ]] && eval "$(direnv hook zsh)"
[[ -f /usr/bin/terraform ]] && autoload -U +X bashcompinit && bashcompinit && complete -o nospace -C /usr/bin/terraform terraform
[[ -f /opt/homebrew/bin/rbenv ]] && eval "$(rbenv init - zsh)"
[[ -f /usr/share/nvm/init-nvm.sh ]] && source /usr/share/nvm/init-nvm.sh
# }}}
# finally {{{
stty -ixon
[[ -f $HOME/.zshrc.local ]] && source $HOME/.zshrc.local
# }}}
# vim: set foldmethod=marker :
# vim: set formatoptions& formatoptions-=ro :
# vim: set noexpandtab :