dotfiles / .zsh / .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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#!/usr/bin/env zsh

# Options

export EDITOR='emacsclient'
#export EDITOR='vim'
export PAGER='less'
export BROWSER='open'
# TODO: make this a path inside libakg
#export PYTHONSTARTUP="$HOME/.pythonrc.py"
# TODO: remove this, ~/var/venv/bin/python is on path and is where I
# should install stuff
#export PYTHONPATH=$HOME/.local/lib/python2.7/site-packages
export JAVA_HOME=/usr
export EC2_HOME="$HOME/.ec2"

setopt NO_clobber \
       extended_glob \
       extended_history \
       glob_complete \
       hist_allow_clobber \
       hist_expire_dups_first \
       hist_ignore_all_dups \
       hist_ignore_dups \
       hist_ignore_space \
       hist_reduce_blanks \
       hist_verify \
       share_history \
       interactive_comments \
       list_packed \
       long_list_jobs \
       multios \
       numeric_glob_sort \
       posix_builtins \
       prompt_subst \
       pushd_ignore_dups \
       no_hup \
       no_check_jobs

HISTSIZE=5000
mkdir -p ~/.history.d
if [ $TMUX_SESSION ]; then
    export HISTFILE=~/.history.d/$TMUX_SESSION
else
    export HISTFILE="$ZDOTDIR/.zsh_history"
fi

SAVEHIST=1000

# Disable flow control, which makes ^S and ^Q work
[[ -n "$(command -v stty)" ]] && stty -ixoff -ixon

# Aliases

if [[ "$TERM" != dumb && -n "$(command -v dircolors)" ]]
then
    eval "$(dircolors -b ~/.dir_colors)"
    alias ls='ls --color=auto'
    alias dir='ls --color=auto --format=vertical'
    alias vdir='ls --color=auto --format=long'
else
    export CLICOLOR=1
    export LSCOLORS=ExGxFxdaCxDaDaHbadabec
    LS_COLORS='no=00:fi=00:di=04;34:ln=01;36:pi=40;33:so=01;35:do=01;35:'\
'bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:'\
'st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:'\
'*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:'\
'*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:'\
'*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:'\
'*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:'\
'*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:'\
'*.xwd=01;35:*.flac=01;35:*.mp3=01;35:*.mpc=01;35:*.ogg=01;35:*.wav=01;35:'
    export LS_COLORS
    alias dir='ls --format=vertical'
    alias vdir='ls --format=long'
fi

alias ll='ls -l'
alias la='ls -A'
alias lh='ls -hog'
alias l='ls -CF'

alias rr="rm -r"
alias rrv="rm -rv"
alias rrvf="rm -rvf"

# I never actually use these, but it's good for remembering the tar
# options. 
alias H="history | grep" 
alias E=env
alias envv="env | grep"
alias A=aptitude
alias "apt-show"="apt-cache show"
alias "apt-search"="apt-cache search"
alias "apt-install"="apt-get install"
# Couldn't resist.
alias mp=mplayer

alias grep="grep --color=tty -d skip"
alias grepy=greppy
alias wl="wc -l"

alias lesstail="less +F"
alias lt=lesstail

# easy_install idiocy; make it unzip by default
alias easy_install="easy_install -Z"

alias n="nautilus --no-desktop"

alias ec="emacsclient -n"
alias et="emacsclient -t"

# tmux shortcuts
t()
{
    _tmux-helper neww "$@"
}
alias ta="tmux attach -t"
alias tm="tmux attach -t 0"
alias t0="tmux attach -t 0"
alias t1="tmux attach -t 1"
alias tt="tmux attach -t top"
alias tf0="tmux attach -t fit0"
alias tf1="tmux attach -t fit1"
alias tl="tmux list-sessions"
alias T="tmux new-session -t"

tmux_create_session(){
    tmux new-session -d -s $1
    tmux set-environment -t $1 TMUX_SESSION $2
}

# alias old screen shortcuts to help with the muscle-memory transition
alias sa="ta"
alias sm="tm"
alias sc="tc"
alias sl="tl"


# Mercurial aliases
alias hl="hg log"
alias h5="hg log --limit=5 -v"
alias hc="hg commit -m"
alias hr="hg record -m"
alias hwl="hg diff | wl"
alias hf="hg diff --show-function"
alias hs="hg status"
alias hb="hg branch && hg branches"
alias hu="hg update"


# Git aliases
alias \
    gh='git hist' \
    g='git ' \
    gg='gf ' \
    ggc='gf --cached ' \
    gff='git merge --ff-only ' \
    ghl='git histl' \
    gs='git status' \
    gd='git diff' \
    gdc='git diff --cached' \
    gdl='git diff | wc' \
    gc='git commit' \
    gb='git branch' \
    gl='git lol' \
    gll='git loll' \
    gla='git lola' \
    gco='git checkout' \
    gpush='git push origin HEAD'

# TODO: use a .gitconfig alias instead
gf(){
    git diff -p --color=always $@ |cat
}

# as in 'git diff stat'
gds(){
    git diff --stat --color=always $@ |cat
}


mid(){
    tail -n +$2 $1 | head -n $3
}


alias w='wim'
alias v='wim vc'

alias p="wim prompt"
alias q=p
alias f="fossil"
alias fs="fossil status"
alias ez='python setup.py install --prefix="~/.local"'
alias ezd='python setup.py develop --prefix="~/.local"'
alias P=project

alias real="cd `pwd -P`"
alias reload='. ~/.zsh/.zshrc'



ZLS_COLORS="$LS_COLORS"

alias ll='ls -l' \
      la='ls -A' \
      l='less' \
      grep='grep --color=always' \
      mq='hg -R $(hg root)/.hg/patches' \
      zgrep='zgrep --color=always'

beep()
{
    echo -n '\a'
}

if [[ "$TERM" != dumb && -n "$(command -v colordiff)" ]]
then
    alias diff='colordiff -u'
fi

autoload -U colors && colors

# less niceties

export LESS='-iRS'
export LESS_TERMCAP_mb=${fg_bold[red]}
export LESS_TERMCAP_md=${fg_bold[blue]}
export LESS_TERMCAP_me=$reset_color
export LESS_TERMCAP_se=$reset_color
LESS_TERMCAP_so=$'\e['"${color[bold]};${color[bg-blue]};${color[yellow]}m"
export LESS_TERMCAP_so
export LESS_TERMCAP_ue=$reset_color
export LESS_TERMCAP_us=${fg_bold[green]}

# Completion

zmodload -i zsh/complist
autoload -U compinit && compinit

# Formatting
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format "%{${fg[blue]}%}%d%{$reset_color%}"
zstyle ':completion:*:messages' format "%{${fg[green]}%}%d%{$reset_color%}"
zstyle ':completion:*:warnings' format \
       "%{${fg[red]}%}No matches for:%{$reset_color%} %d"
zstyle ':completion:*:corrections' format \
       "%{${fg[red]}%}%d (errors: %e)%{$reset_color%}"
zstyle ':completion:*' group-name ''
[[ -n "$LS_COLORS" ]] && zstyle ':completion:*' list-colors \
                                "${(s.:.)LS_COLORS}"

# Rehash PATH for new commands
_force_rehash()
{
    if [[ $CURRENT -eq 1 ]]
    then
        rehash
    elif [[ $CURRENT -eq 2 && "$words[1]" = sudo ]]
    then
        rehash
    fi
    return 1
}


# run something and exit
R(){$@ & exit}

# Matching
zstyle ':completion:*' use-cache on
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' \
                                    'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle -e ':completion:*' completer '
    if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]]
    then
        _last_try="$HISTNO$BUFFER$CURSOR"
        reply=(_force_rehash _complete _match _prefix)
    else
        reply=(_ignored _correct _approximate _complete)
    fi'

zstyle ':completion:*match:*' original only
zstyle -e ':completion:*:approximate:*' \
           max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:(cp|emacs|diff|kill|ls|rm|rmdir|scp|vim|vimdiff):*' \
       ignore-line yes
zstyle -e ':completion:*:processes' command '
    if (( $funcstack[(eI)$_comps[sudo]] ))
    then
       reply="ps axho user,pid,command"
    else
       reply="ps xho pid,command"
    fi'
zstyle -e ':completion:*:processes-names' command '
    if (( $funcstack[(eI)$_comps[sudo]] ))
    then
       reply="ps axho command"
    else
       reply="ps xho command"
    fi'


# playing with charmap...
# ∀∃∄¬∧∨
# ∴ ⋙ ↖ ☃☄★☆☉☢☠☎☐☑☒☘☣☤☥☦☩☪☫☭☮☯☸☹☺☻☼☿♀♁♂♐♻♼♽♿⚜⚕⚢⚣⚠⚤⚥⚦⚧⚪
PROMPT=
RPROMPT=""

# Window title

case $TERM in
    xterm*|rxvt*)
        precmd () { print -Pn "\e]0;%n@%M\a" }
        ;;
    *)
        ;;
esac

# Load/configure key bindings

bindkey -e # Revert back to emacs mode
WORDCHARS='' # Use emacs-style word matching

autoload -U select-word-style
select-word-style normal
zstyle ':zle:*' word-style subword

autoload -U down-line-or-beginning-search up-line-or-beginning-search
zle -N down-line-or-history down-line-or-beginning-search
zle -N up-line-or-history up-line-or-beginning-search

# Make ^W work like it does in bash (while leaving other bindings alone)
zle -N backward-kill-word-bash backward-kill-word-match
zstyle ':zle:backward-kill-word-bash' word-style whitespace

bindkey '^Q' quoted-insert \
        '^U' vi-kill-line \
        '^W' backward-kill-word-bash

if [[ "$TERM" = xterm* ]]
then
    bindkey '\e[1;5A' up-line-or-history \
            '\e[1;3A' up-line-or-history \
            '\e[1;5B' down-line-or-history \
            '\e[1;3B' down-line-or-history \
            '\e[1;5D' backward-word \
            '\e[1;3D' backward-word \
            '\e[1;5C' forward-word \
            '\e[1;3C' forward-word
fi

autoload -U zkbd
[[ ! -d "$ZDOTDIR/.zkbd" ]] && mkdir "$ZDOTDIR/.zkbd"
[[ ! -f "$ZDOTDIR/.zkbd/$TERM-$VENDOR-$OSTYPE" ]] && zkbd
source "$ZDOTDIR/.zkbd/$TERM-$VENDOR-$OSTYPE"

[[ -n "${key[Backspace]}" ]] && bindkey "${key[Backspace]}" \
                                        backward-delete-char
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" beep
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beep
[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" beep
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history && \
                         bindkey "\e${key[Up]}" up-line-or-history
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char && \
                           bindkey "\e${key[Left]}" backward-word
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history && \
                           bindkey "\e${key[Down]}" down-line-or-history
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char && \
                            bindkey "\e${key[Right]}" forward-word
[[ -n "${key[Control-Left]}" ]] && bindkey "${key[Control-Left]}" backward-word
[[ -n "${key[Control-Right]}" ]] && bindkey "${key[Control-Right]}" \
                                            forward-word

# Prompt
PROMPT="%{${fg[yellow]}%}%D\
%{${fg[default]}%}|\
%{%B${fg[yellow]}%}%*\
%{%b${fg[default]}%}|\
%{${fg[cyan]}%}%m\
%{${fg[default]}%}|\
%{%B${fg[cyan]}%}%~\
%{$reset_color%}\

%{${fg[cyan]}%}$%{$reset_color%} "
RPROMPT=""

# Window title
precmd () { print -Pn "\e]0;%m:\a" }

propy="/home/akg/var/python/environments/propane/bin/python"
cmd(){ $propy ~/srv/libakg/libakg/cmd.py $@     }
wim(){ $propy ~/srv/libakg/libakg/cmd.py wim $@ }
f(){   $propy ~/srv/libakg/libakg/cmd.py f $@   }
j(){   $propy ~/srv/libakg/libakg/cmd.py j $@   }
s(){   $propy ~/srv/libakg/libakg/cmd.py s $@   }
eval `cmd wim ppath clean check set`


# Per-session zsh customizations
if [[ -n "$TMUX_SESSION" && -f ~/.config/zshrc.d/$TMUX_SESSION ]]; then
    . ~/.config/zshrc.d/$TMUX_SESSION
fi
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.