-
Notifications
You must be signed in to change notification settings - Fork 4
/
.zshrc
332 lines (278 loc) · 6.82 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
HISTFILE=~/.histfile
HISTSIZE=100000
SAVEHIST=500000
WORDCHARS='*?_.[]~&;!#$%^(){}<>'
setopt auto_resume
setopt extendedglob
setopt notify
setopt interactive_comments
setopt extended_history
setopt inc_append_history
setopt share_history
setopt hist_find_no_dups
setopt hist_ignore_dups
setopt hist_reduce_blanks
setopt hist_verify
setopt hist_ignore_space
setopt brace_ccl
setopt correct
setopt long_list_jobs
setopt magic_equal_subst
setopt print_exit_value
setopt hash_cmds
setopt rm_star_wait
setopt short_loops
unsetopt autocd
unsetopt nomatch
unsetopt beep
unsetopt flow_control
bindkey -e
##
# plugin
##
# zplugin
source ~/.zinit/bin/zinit.zsh
# zinit load "zinit-zsh/z-a-bin-gem-node"
zinit load "zsh-users/zsh-completions"
zinit load "zsh-users/zsh-history-substring-search"
zinit load "zsh-users/zsh-syntax-highlighting"
zinit load "zsh-users/zsh-autosuggestions"
zinit ice as"program" from"gh-r"
zinit load "junegunn/fzf"
zinit ice as"program" from"gh-r" mv"jq* -> jq"
zinit load "stedolan/jq"
zinit ice as"program" from"gh-r" pick"ghq_*/ghq"
zinit load "x-motemen/ghq"
zinit ice as"program" pick"git-icdiff"
zinit load "jeffkaufman/icdiff"
zinit ice as"program" from"gh-r" mv"sops* -> sops" bpick"*darwin*"
zinit load "mozilla/sops"
zinit ice from"gh-r" as"program" pick"zoxide-*-x86_64-apple-darwin/zoxide"
zinit load "ajeetdsouza/zoxide"
zinit ice from"gh-r" as"program" pick"bin/exa"
zinit load "ogham/exa"
zinit ice from"gh-r" as"program"
zinit load "zigtools/zls"
HISTDB_TABULATE_CMD=(sed -e $'s/\x1f/\t/g')
zinit ice depth"1" # git clone depth
zinit load "larkery/zsh-histdb"
##
# key binding
##
zmodload zsh/terminfo
# history-substring-search
bindkey -M emacs '^P' history-substring-search-up
bindkey -M emacs '^N' history-substring-search-down
bindkey -M emacs "$terminfo[kcbt]" reverse-menu-complete
bindkey -M emacs "\e#" pound-insert
##
# color
##
autoload -U colors; colors
##
# completion
##
setopt alwaystoend
setopt completeinword
setopt automenu
setopt autolist
setopt autoparamslash
setopt listpacked
unsetopt menucomplete
zstyle ':completion:*:*:*:*:*' menu select
# use cache
zstyle ':completion::complete:*' use-cache on
# fuzzy match mistyped completions
zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric
##
# helper
##
# random hash
function random_short_hash {
PYENV_VERSION="2" pyenv exec python -c 'import os, hashlib; print hashlib.sha256(os.urandom(2048)).hexdigest()[:7]'
}
# bc - An arbitrary precision calculator language
function = {
echo "$@" | bc -l
}
alias calc==
function =2 {
= "obase=2; $@"
}
function =16 {
= "obase=16; $@"
}
# `du` prettified
function duf {
du -sk "$@" | sort -n | while read size fname; do
for unit in k M G T P E Z Y; do
if [ $size -lt 1024 ]; then
echo -e "${size}${unit}\t${fname}"
break
fi
size=$((size/1024))
done
done
}
# docker
function docker-clear {
docker images -f dangling=true -q | xargs -I{} docker rmi -f {}
}
function docker-run {
docker run -it -P -v ${HOME}:/home/kane "$@"
}
function docker-run1 {
docker run -it --rm -P -v ${HOME}:/home/kane "$@"
}
function docker-runbg {
docker run -d -P -v ${HOME}:/home/kane "$@"
}
# find process
function fps { ps aux | grep "$1" }
# get ssl fingerprint, arg 1 is <host>:<port>
function sslfp {
openssl s_client -connect $1 < /dev/null 2>/dev/null | openssl x509 -fingerprint -noout -in /dev/stdin
}
function lo {
$* "$(`fc -ln -1` | fzy)"
}
function _mvim_open_in_tab {
mvim --remote-tab-silent "${@:-.}"
}
##
# alias
##
alias b=brew
alias c=clear
alias ls=exa
alias vi=vim
alias mvim='_mvim_open_in_tab'
alias j="z"
alias tl="tail"
alias hd="head"
alias l="less"
alias lm="ls -lahF"
alias km="k -ah"
alias l1="ls -1"
alias findn="find . -name"
alias tmux="tmux -2 -u"
alias ta="tmux attach"
alias csk="brew cask"
alias ec="open -a Emacs.app"
alias em="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n"
alias g="git"
alias ncpu="getconf _NPROCESSORS_ONLN"
alias dr=docker-run
alias dr1=docker-run1
alias drb=docker-runbg
alias rcopy="rsync -avz --progress -h"
alias rmove="rsync -avz --progress -h --remove-source-files"
alias rupdate="rsync -avzu --progress -h"
alias rsync-synchronize="rsync -avzu --delete --progress -h"
alias gg='__gg () { open "https://www.google.com/search?q=$*" }; __gg'
alias wghq='GHQ_ROOT=~/work/repos ghq'
## nvim alias
if command -v nvim &>/dev/null; then
alias vim=nvim
alias vi=nvim
fi
# Improve terminal title
case "${TERM}" in
kterm*|xterm*|vt100)
precmd() {
echo -ne "\033]0;${USER}@${HOST%%.*}:${PWD}\007"
}
;;
esac
# jump to source dir managed by _motemen/ghq_
function js {
local srcpath=$(ghq list -p \
| fzy --prompt "repo> " --query "$*")
if [ -z "$srcpath" ]; then
return
fi
pushd "$srcpath"
}
# jog
function jog() {
sqlite3 $HOME/.histdb/zsh-history.db "
SELECT
replace(commands.argv, '
', '
')
FROM commands
JOIN history ON history.command_id = commands.id
JOIN places ON history.place_id = places.id
WHERE history.exit_status = 0
AND dir = '${PWD}'
AND places.host = '${HOST}'
AND commands.argv != 'jog'
AND commands.argv NOT LIKE 'z %'
AND commands.argv NOT LIKE 'cd %'
AND commands.argv != '..'
ORDER BY start_time DESC
LIMIT 10
"
}
# ssh interactively select host
function sshi {
local q="$1"
if [ -n "$q" ]; then
shift
local opts="$*"
fi
local host=$(cut -d' ' -f1 ~/.ssh/known_hosts \
| sort \
| fzy --prompt 'host> ' --query "$q")
if [ -z "$host" ]; then
return
fi
ssh "$host" "$opts"
}
if [ -f ~/.zshrc.custom ]; then
. ~/.zshrc.custom
fi
function install_pypkg {
PYENV_VERSION=`pyenv global` pyenv exec pip install -r $HOME/requirements.txt "$1"
}
function install_gopkg {
local pkgs=(
# linter
github.com/alecthomas/gometalinter
github.com/golang/lint/golint
github.com/jgautheron/goconst/cmd/goconst
github.com/opennota/check/cmd/varcheck
github.com/opennota/check/cmd/aligncheck
github.com/opennota/check/cmd/structcheck
golang.org/x/tools/cmd/gotype
# auto complete
github.com/nsf/gocode
# formatting
golang.org/x/tools/cmd/goimports
# tagging
github.com/jstemmer/gotags
github.com/rogpeppe/godef
# analysis
golang.org/x/tools/cmd/guru
github.com/jstemmer/gotags
github.com/juntaki/gogtags
# dependency
github.com/golang/dep/cmd/dep
# build
github.com/mitchellh/gox
# exec
github.com/motemen/github-list-starred
)
for p in $pkgs; do
go get -v -u $p
done
}
# python
export VIRTUAL_ENV_DISABLE_PROMPT=1
# zoxide
eval "$(zoxide init zsh)"
# starship
eval "$(starship init zsh)"
# vim:ft=zsh