-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathzshrc
335 lines (309 loc) · 12 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
# .zshrc by Jordan Lewis
# Environment variables {{{
fpath=(/usr/local/share/zsh/site-functions/ $fpath)
HISTFILE=~/.zshhistory # What histfile are we using?
HISTSIZE=100000 # Big = better
SAVEHIST=7000 # When to save to the file?
TERM=xterm-256color
export SHELL=`which zsh` # New shells don't open bash
export EDITOR=vim # Use vim!
export GREP_OPTIONS='--color=auto' # Color my greps
export GOPATH=$HOME/go
if [ $(uname) = Linux ]; then
alias ls='ls --color=auto'
else
export CLICOLOR=1
fi
export NNTPSERVER=news-server.nyc.rr.com # Use my ISP's news server
export PERL5LIB='/Users/jlewis/.perl/'
export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-12.0.1.jdk/Contents/Home/
export PLY_HOME=~/ext/ply/dist/ply
export EC2_HOME="/usr/local/Cellar/ec2-api-tools/1.5.5.0/jars"
export EC2_PRIVATE_KEY="/Users/jordan/.aws/pk-IFJE2TQ7VDYZHJW4ER46OO7VGSSHVGDP.pem"
export EC2_CERT="/Users/jordan/.aws/cert-IFJE2TQ7VDYZHJW4ER46OO7VGSSHVGDP.pem"
export EC2_REGION=us-east-1
export AWS_RDS_HOME="/usr/local/Cellar/rds-command-line-tools/1.12.002/libexec/"
export AWS_CLOUDFORMATION_HOME="/usr/local/Cellar/aws-cfn-tools/1.0.9/jars/"
export CLUSTER=Your Cluster Name Goes Here # This will get changed based on the cluster you're working on.
export C_INCLUDE_PATH=/usr/local/Cellar/zookeeper/3.4.3/include/zookeeper/
export PYTHONSTARTUP="/Users/jordan/.pythonstartup"
# }}}
# Setopts {{{
setopt auto_cd # If I type a directory, assume I mean to cd to it
setopt auto_pushd # Automatically push directories onto the stack
setopt badpattern # Print an error message on badly formed glob
#setopt cdablevars # So we can cd to metachars like ~
setopt correct # Attempt typo corrections
setopt complete_in_word #
#setopt extended_glob # Allow ~ # ^ metachars in globbing
# disabled - this makes it so you can't use the ^ revision spec thing with git!
setopt extended_history # More information in history
setopt hist_ignore_space # Don't put space-prepended commands in the history
setopt interactivecomments # Allow comments even in the interactive shell
setopt listpacked # Menucomplete can use different col widths
setopt magicequalsubst # echo foo=~/bar -> foo/home/jlewis/bar
#setopt markdirs # Append / to all glob-completed dirs
# disabled - given a dirtree foo/bar/baz.txt, cp -R foo/* /tmp/ causes baz.txt
# to be sent to /tmp/. no good!
setopt multios # Allow multiple redirection!
setopt nobanghist # Disable ! replacement
setopt nobeep # Don't beep
setopt no_flowcontrol # No stupid flow control!
setopt nullglob # Delete a glob if it doesn't match anything
setopt promptsubst
setopt pushd_ignore_dups # Don't push multiple copies of a directory
# }}}
# Autoloads {{{
autoload -U compinit; compinit
autoload -U predict-on
autoload -U edit-command-line
autoload -U copy-earlier-word
autoload -U add-zsh-hook
autoload -U bashcompinit && bashcompinit
# }}}
# Zle {{{
zle -N predict-on;
zle -N predict-off;
zle -N edit-command-line
zle -N copy-earlier-word
# }}}
# Zstyles {{{
zstyle ':completion::complete:*' use-cache 1 # uses completion cache
zstyle ':completion::complete:*' cache-path ~/.zshcache
zstyle ':completion:*' menu select # menu-style completion
zstyle ':completion:*:functions' ignored-patterns '_*' # no missing completions
# }}}
# Bindkeys {{{
bindkey -v # Use vim bindings
bindkey "^A" beginning-of-line # Like in bash, for memory
bindkey "^E" end-of-line # Like in bash
bindkey "^N" accept-and-infer-next-history # Enter; pop next history event
bindkey "^O" push-line # Pushes line to buffer stack
bindkey "^P" get-line # Pops top of buffer stack
bindkey "^R" history-incremental-search-backward # Like in bash, but should !
bindkey "^Y" copy-earlier-word
bindkey "^Z" accept-and-hold # Enter and push line
bindkey " " magic-space # Expands from hist (!vim )
bindkey "^\\" pound-insert # As an alternative to ctrl-c; will go in hist
bindkey "\e[3~" delete-char # Enable delete
bindkey "^x^e" edit-command-line
#bindkey "^Q" predict-off # Disable sweet complete-as-you-type
#bindkey "..." predict-on # Enable sweet complete-as-you-type
# }}}
# Aliases {{{
# Misc {{{
alias cp='nocorrect cp' # Don't correct this cmd
alias mkdir='nocorrect mkdir' # Don't correct this cmd
alias mv='nocorrect mv' # Don't correct this cmd
alias touch='nocorrect touch' # Don't correct this cmd
alias sl='sl -l' # ... dumb
alias termcast='telnet 213.184.131.118 37331' # noway.ratry.ru 37331
alias slurp='wget -r --no-parent'
alias deflac='for file in *.flac; do $(flac -cd "$file" | lame -V 0 --vbr-new - "${file%.flac}.mp3"); done' # convert all flacs in directory to v0
# add git-number support if it exists
which hub &> /dev/null
if [ $? -eq 0 ]; then
gitbin=$(which hub)
else
gitbin=$(which git)
fi
which git-number &> /dev/null
if [ $? -eq 0 ]; then
numbercommands=(add rm diff reset checkout co restore)
git()
{
if [ $1 = "status" ]; then
$gitbin number;
elif [ ${numbercommands[(r)$1]} ]; then
$gitbin number "$@"
else
$gitbin "$@"
fi
}
else
alias git='nocorrect git'
fi
alias quickinstall='mvn clean -DskipTests install -Dmaven.test.skip=true -Dfindbugs.skip=true -Dinstrument.skip=true'
# }}}
# Shells {{{
alias bh='ssh [email protected]'
alias bhsec='ssh [email protected]'
alias ch='ssh [email protected]'
#alias chana='ssh [email protected]' # chana, my mbp.. need dyndns
alias cs='ssh [email protected]'
alias echoduet='ssh [email protected]'
alias econ='ssh [email protected]'
#alias enwina='ssh -X 192.168.0.2' # This is/was my HP
alias harper='TERM=xterm ssh [email protected]'
alias mookmo='ssh [email protected]'
alias sartak='ssh [email protected]'
alias sd='ssh [email protected]'
alias yiff='ssh [email protected]'
# }}}
# Games {{{
alias cao='TERM=rxvt telnet crawl.akrasiac.org' # urxvt-color screws up
alias nao='TERM=rxvt telnet nethack.alt.org' # urxvt-color screws up
alias sco='TERM=rxvt telnet slashem.crash-override.net'
alias spork='TERM=rxvt telnet sporkhack.nineball.org'
# }}}
# Shortcuts {{{
alias '..'='cd ..' # cd .. takes too much effort!
alias 'web'='python -m SimpleHTTPServer' # hosts . on :8000
alias bc='bc -q -l' # no warranty thing; loads math lib
alias broadcast='ifconfig | grep broadcast | tail -c 16'
alias c='pygmentize -O style=monokai -f console256 -g'
alias cls='perl -e "print \"\e[2J\""' # prints a clearscreen - for termcast
alias dotperl='rsync -av lib/* ~/.perl/'
alias duf='du -sk * | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\'
alias hide='xset dpms force standby; exit' # kills my LCD monitor
alias l='ls' # sometimes I think I'm still on a MUD/MOO
alias mouse='xmodmap -e "pointer = 1 2 3 6 7 8 9 10 4 5"' # fixes my buttons
alias ncscan='nc -v -z' # scans ports with netcat
alias nmapscan='nmap -p' # scans ports with nmap
alias probe='ping -i 50 `ifconfig | grep broadcast | tail -c 16`'
alias reload='source ~/.zshrc' # re-sources this
alias restartx='sleep 5; startx' # restarts X!
alias tdA="todo -A" # displays all todo items
alias usage='du -hs *' # nicely displays disk usage of items in pwd
which htop>/dev/null && alias top='htop' # prettier version of top if it exists
# }}}
# Git {{{
alias g='git'
alias gs='git status'
alias gd='git diff'
alias ga='git add'
alias gl='git log'
# }}}
# Global shortcuts {{{
alias -g ...='../..' # Ease of going backward
alias -g ....='../../..' # Yes
alias -g .....='../../../..' # YES
alias -g G='|egrep' # cat biglongfile G cheese
alias -g H='|head' # cat biglongfile H
alias -g L='|less' # cat biglongfile L
alias -g T='|tail' # cat biglongfile T
alias -g W='|wc' # cat biglongfile W
# }}}
# }}}
# Prompt {{{
source ~/.zshprompt
# }}}
# zplug {{{
export ZPLUG_HOME=/usr/local/opt/zplug
source $ZPLUG_HOME/init.zsh
zplug "zsh-users/zsh-syntax-highlighting"
zplug "changyuheng/fz", defer:1
zplug "rupa/z", use:z.sh
zplug load
# }}}
# Print to stdout {{{
fortune 2>/dev/null || true # essential!
# }}}
# OPAM configuration
. /Users/jordan/.opam/opam-init/init.zsh > /dev/null 2> /dev/null || true
# FZF configuration
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget-accept() {
local selected num
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
selected=$(fc -l 1 |
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --print-query --tac -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort,left:print-query,right:print-query $FZF_CTRL_R_OPTS --query=${(q)LBUFFER} +m" $(__fzfcmd))
local ret=$?
lines=(${(f)selected})
function setbuffer() {
BUFFER=$lines[1]
}
zle -N setbuffer
local accept=1
if [[ $ret -eq 1 ]]; then
zle setbuffer
accept=0
elif [[ -n $selected ]]; then
local out=$lines[2]
num=(${(s. .)out})
num=${num[1]}
if [[ -n $num ]]; then
zle vi-fetch-history -n $num
else
zle setbuffer
accept=0
fi
fi
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
if [[ $accept -eq 1 ]]; then
zle accept-line
fi
return $ret
}
export FZF_CTRL_T_OPTS="--bind=ctrl-d:preview-page-down,ctrl-u:preview-page-up --preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
export FZF_CTRL_T_COMMAND="rg --files"
export FZF_CTRL_R_OPTS="--height 5 --inline-info"
zle -N fzf-file-widget
bindkey '^F' fzf-file-widget
zle -N fzf-history-widget-accept
bindkey '^R' fzf-history-widget-accept
export FZF_DEFAULT_COMMAND='rg --files'
# GIT heart FZF
# -------------
is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
fzf-down() {
fzf --height 50% "$@" --border
}
gf() {
is_in_git_repo || return
git -c color.status=always status --short |
fzf-down -m --ansi --nth 2..,.. \
--preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500' |
cut -c4- | sed 's/.* -> //'
}
gb() {
is_in_git_repo || return
git branch -a --color=always | grep -v '/HEAD\s' | sort |
fzf-down --ansi --multi --tac --preview-window right:70% \
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1) | head -'$LINES |
sed 's/^..//' | cut -d' ' -f1 |
sed 's#^remotes/##'
}
gt() {
is_in_git_repo || return
git tag --sort -version:refname |
fzf-down --multi --preview-window right:70% \
--preview 'git show --color=always {} | head -'$LINES
}
gh() {
is_in_git_repo || return
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always |
fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \
--header 'Press CTRL-S to toggle sort' \
--preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always | head -'$LINES |
grep -o "[a-f0-9]\{7,\}"
}
gr() {
is_in_git_repo || return
git remote -v | awk '{print $1 "\t" $2}' | uniq |
fzf-down --tac \
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1} | head -200' |
cut -d$'\t' -f1
}
join-lines() {
local item
while read item; do
echo -n "${(q)item} "
done
}
bind-git-helper() {
local c
for c in $@; do
eval "fzf-g$c-widget() { local result=\$(g$c | join-lines); zle reset-prompt; LBUFFER+=\$result }"
eval "zle -N fzf-g$c-widget"
eval "bindkey '^g^$c' fzf-g$c-widget"
done
}
bind-git-helper f b t r h
unset -f bind-git-helper
alias csql="~/go/src/github.com/cockroachdb/cockroach/cockroach sql --insecure"
alias cdemo="~/go/src/github.com/cockroachdb/cockroach/cockroach demo --empty"