-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
385 lines (345 loc) · 11.2 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
376
377
378
379
380
381
382
383
384
385
## -*- mode: sh; coding: utf-8-unix -*-
###
# Set shell options
###
setopt auto_list
setopt auto_menu
setopt auto_cd
setopt auto_name_dirs
setopt auto_remove_slash
setopt correct
setopt prompt_subst
setopt print_eight_bit
setopt auto_pushd
setopt pushd_ignore_dups
setopt rm_star_silent
setopt sun_keyboard_hack
setopt extended_glob
setopt list_types
setopt no_beep
setopt no_flowcontrol
setopt always_last_prompt
setopt cdable_vars
setopt sh_word_split
setopt auto_param_keys
setopt extended_history
setopt append_history
setopt magic_equal_subst
setopt hist_ignore_space
setopt hist_expire_dups_first
setopt hist_ignore_all_dups
setopt hist_reduce_blanks
setopt share_history
setopt interactivecomments
HISTFILE="$HOME/.zsh-history"
HISTSIZE=10000
SAVEHIST=10000
WORDCHARS="`echo $WORDCHARS|sed 's!/!!'`"
if which dircolors > /dev/null; then
eval `dircolors -b`
fi
bindkey -e
bindkey "^[[1;5C" emacs-forward-word
bindkey "^[[1;5D" emacs-backward-word
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
alias a=alias
a rm=" rm -I"
a sudo=" sudo"
a ls="ls -F --color --show-control-chars --group-directories-first"
a ll="ls -l"
a la="ll -a"
a patch="patch -b --verbose"
a c="/usr/bin/clear"
a h="history -E"
a d="date"
a j="jobs"
a ec="emacsclient"
a dpkg='COLUMNS=${COLUMNS:-80} dpkg'
a psa="ps axuww"
a ssh="ssh -A"
a ag="ag --pager 'less -R'"
a grep="grep --color=auto"
a open='xdg-open'
function history-all() {
history -E 1
}
function iscygwin() {
[[ "$OSTYPE" = cygwin ]] && return 0
return 1
}
function isemacs() {
[[ "$INSIDE_EMACS" != "" ]] && return 0
return 1
}
function istmux() {
[[ "$TMUX" != "" ]] && return 0
return 1
}
function isscreen() {
istmux && return 1
[[ "${TERM[0,6]}" = screen ]] && return 0
return 1
}
function isdumb() {
[[ "${TERM[0,4]}" = dumb ]] && return 0
return 1
}
#-------------------------------------------------------------------------
# Zinit
#-------------------------------------------------------------------------
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
print -P "%F{33}▓▒░ %F{220}Installing DHARMA Initiative Plugin Manager (zdharma/zinit)…%f"
command mkdir -p "$HOME/.zinit" && command chmod g-rwX "$HOME/.zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.zinit/bin" && \
print -P "%F{33}▓▒░ %F{34}Installation successful.%f" || \
print -P "%F{160}▓▒░ The clone has failed.%f"
fi
source "$HOME/.zinit/bin/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
zinit ice wait lucid
zinit light zsh-users/zsh-completions
zinit light zdharma-continuum/fast-syntax-highlighting
#zinit ice pick"async.zsh" src"pure.zsh"
#zinit light sindresorhus/pure
zinit snippet OMZL::git.zsh
zinit snippet OMZP::git
zinit snippet OMZP::rsync
zinit snippet OMZP::yarn
#zinit ice from"gh-r" as"program"
#zinit load junegunn/fzf-bin
#zinit ice as"program" has"tmux" pick"bin/fzf-tmux"
#zinit load junegunn/fzf
zinit pack for fzf
fpath=($HOME/.zsh/anyframe-custom(N-/) $fpath)
zinit light mollifier/anyframe
zinit ice as"program" pick"$ZPFX/bin/pfetch" make"PREFIX=$ZPFX"
zinit light dylanaraps/pfetch
zinit ice as"program" has"tmux" pick"bin/xpanes"
zinit light "greymd/tmux-xpanes"
zinit ice from"gh-r" as"program" mv"docker-compose* -> docker-compose" bpick"*linux*"
zinit load docker/compose
zinit wait lucid is-snippet as"completion" for \
OMZP::docker-compose/_docker-compose
#-------------------------------------------------------------------------
# Completion configuration
#-------------------------------------------------------------------------
fpath=($HOME/.zsh/completions(N-/) $fpath)
autoload -Uz compinit && compinit
zstyle ':completion:*' verbose yes
zstyle ':completion:*' completer _expand _complete _match _prefix _approximate _list _history
zstyle ':completion:*:messages' format '%F{yellow}%d%f'
zstyle ':completion:*:warnings' format '%F{red}%BNo matches for:%b %F{yellow}%d%f'
zstyle ':completion:*:descriptions' format '%F{yellow}%B[%d]%b%f'
zstyle ':completion:*:corrections' format '%F{yellow}%B[%d] %F{red}(errors: %e)%b%f'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:default' menu select true
zstyle ':completion:*' use-cache true
zstyle ':completion:*' ignore-parents parent pwd ..
zstyle ':completion:*:manuals' separate-sections true
#-------------------------------------------------------------------------
# cdr
#-------------------------------------------------------------------------
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':completion:*' recent-dirs-insert both
zstyle ':chpwd:*' recent-dirs-max 500
zstyle ':chpwd:*' recent-dirs-default true
zstyle ':chpwd:*' recent-dirs-pushd true
#-------------------------------------------------------------------------
# anyframe
#-------------------------------------------------------------------------
zstyle ":anyframe:selector:" use fzf
if istmux; then
zstyle ":anyframe:selector:fzf:" command 'fzf-tmux --extended --exact --no-sort --cycle'
fi
bindkey '^[d' anyframe-widget-cdr
bindkey '^r' anyframe-widget-put-history
bindkey '^xb' anyframe-widget-checkout-git-branch
bindkey '^xg' anyframe-widget-cd-ghq-repository
bindkey '^xk' anyframe-widget-kill
bindkey '^xi' anyframe-widget-insert-git-branch
bindkey '^xf' anyframe-widget-insert-filename
bindkey '^xc' anyframe-widget-insert-docker-container-id
#-------------------------------------------------------------------------
# zmv
#-------------------------------------------------------------------------
autoload -Uz zmv
alias zmv='noglob zmv -W'
#-------------------------------------------------------------------------
# abbrev
#-------------------------------------------------------------------------
typeset -A abbreviations
abbreviations=(
"L" "| less"
"G" "| grep"
"X" "| xargs"
"T" "| tail"
"C" "| cat"
"W" "| wc"
"A" "| awk"
"S" "| sed"
"E" "2>&1 > /dev/null"
"N" "> /dev/null"
"P" "| peco"
'be' 'bundle exec'
'de' 'docker exec -it'
)
function magic-abbrev-expand() {
local MATCH
LBUFFER=${LBUFFER%%(#m)[-_a-zA-Z0-9]#}
LBUFFER+=${abbreviations[$MATCH]:-$MATCH}
zle self-insert
}
function no-magic-abbrev-expand() {
LBUFFER+=' '
}
zle -N magic-abbrev-expand
zle -N no-magic-abbrev-expand
bindkey " " magic-abbrev-expand
bindkey "^x " no-magic-abbrev-expand
#-------------------------------------------------------------------------
# fancy prompt
#-------------------------------------------------------------------------
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
[ -f /etc/debian_chroot ] && debian_chroot=`cat /etc/debian_chroot`
PROMPT='%(?.%F{cyan}.%F{red})%B`whoami`@%m${debian_chroot:+($debian_chroot)}%b%f%# '
zstyle ':vcs_info:*' enable git svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' get-revision true
zstyle ':vcs_info:git:*' stagedstr "+"
zstyle ':vcs_info:git:*' unstagedstr "-"
zstyle ':vcs_info:*' formats ':%F{green}%b%F{red}%u%c'
zstyle ':vcs_info:*' actionformats ':%F{green}%b%F{red}%u%c(%a)'
function _precmd_vcs_info () {
LANG=en_US.UTF-8 vcs_info
}
add-zsh-hook precmd _precmd_vcs_info
function rprompt_shorten_current_path () {
# fish like
echo ${${:-/${(j:/:)${(M)${(s:/:)${(D)PWD:h}}#(|.)[^.]}}/${PWD:t}}//\/~/\~}
}
RPROMPT='%F{yellow}[%(5~,`rprompt_shorten_current_path`,%~)${vcs_info_msg_0_}%F{yellow}]%f'
function _precmd_update_term_title () {
isemacs || echo -ne "\033]0;${USER}@${HOST}:${PWD/$HOME/~}\007"
}
add-zsh-hook precmd _precmd_update_term_title
function _preexec_update_window_title () {
# screen/tmux のタイトルを更新
if isemacs; then return; fi
if isscreen || istmux; then
emulate -L zsh
local -a cmd; cmd=(${(z)2})
case $cmd[1] in
fg)
if (( $#cmd == 1 )); then
cmd=(builtin jobs -l %+)
else
cmd=(builtin jobs -l $cmd[2])
fi
;;
%*)
cmd=(builtin jobs -l $cmd[1])
;;
cd)
if (( $#cmd == 2 )); then
cmd[1]=$cmd[2]
fi
;&
*)
echo -ne "\033k$cmd[1]:t\033\\"
return
;;
esac
local -A jt; jt=(${(kv)jobtexts})
$cmd >>(read num rest
cmd=(${(z)${(e):-\$jt$num}})
echo -ne "\033k$cmd[1]:t\033\\") 2>/dev/null
fi
}
add-zsh-hook preexec _preexec_update_window_title
#-------------------------------------------------------------------------
function utf8() {
export LANG=ja_JP.UTF-8
isscreen && screen -X encoding utf8
}
function euc() {
export LANG=ja_JP.EUC-JP
isscreen && screen -X encoding euc
}
function sjis() {
export LANG=ja_JP.SJIS
isscreen && screen -X encoding sjis
}
function git-pull-subdirs() {
if which parallel > /dev/null; then
find -maxdepth 2 -type d -name '.git' | parallel 'DIR={//} ; echo ">>" $DIR; cd $DIR ; git pull --rebase'
else
local gitdir
for gitdir in $(find -maxdepth 2 -type d -name '.git'); do
(
local dir=$(dirname $gitdir)
echo '>>' $dir
cd $dir && git pull --rebase
)
done
fi
}
function resume-ssh-agent() {
local agent
agent=`which wsl2-ssh-agent`
if [ -e "${agent}" ]; then
eval `$agent`
return
fi
if [ -z "$SSH_AUTH_SOCK" -o ! -S "$SSH_AUTH_SOCK" ]; then
test -e "$HOME/.ssh/ssh_agent.env" && source "$HOME/.ssh/ssh_agent.env"
else
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK; export SSH_AUTH_SOCK" | \
tee "$HOME/.ssh/ssh_agent.env" | \
awk 'BEGIN {FS="[=;]"} {printf "setenv %s %s\n", $1, $2}' > "$HOME/.ssh/ssh_agent.screenrc"
fi
agent=`which ssh-agent`
if [ ! -e "${agent}" ]; then
echo missing ssh-agent
elif [ -z "$SSH_AUTH_SOCK" -o ! -S "$SSH_AUTH_SOCK" ]; then
$agent | grep -e '^SSH_' | tee "$HOME/.ssh/ssh_agent.env" | \
awk 'BEGIN {FS="[=;]"} {printf "setenv %s %s\n", $1, $2}' > "$HOME/.ssh/ssh_agent.screenrc"
source "$HOME/.ssh/ssh_agent.env"
fi
}
resume-ssh-agent
#-------------------------------------------------------------------------
if isdumb; then
unsetopt zle
unsetopt prompt_cr
unsetopt prompt_subst
unfunction precmd
unfunction preexec
PS1='$ '
fi
if isemacs; then
unsetopt prompt_cr
PROMPT=$RPROMPT$'\n'$PROMPT
unset RPROMPT
if [[ "$INSIDE_EMACS" = 'vterm' ]] \
&& [[ -n ${EMACS_VTERM_PATH} ]] \
&& [[ -f ${EMACS_VTERM_PATH}/etc/emacs-vterm-zsh.sh ]]; then
source ${EMACS_VTERM_PATH}/etc/emacs-vterm-zsh.sh
fi
fi
# Start tmux
if ! isemacs && ! istmux && ! isscreen && ! isdumb && which tmux > /dev/null; then
ID=`tmux ls | grep -vm1 attached | cut -d: -f1`
if [[ -z "$ID" ]]; then
tmux new-session
else
tmux attach-session -t $ID
fi
fi