forked from adragomir/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
1779 lines (1535 loc) · 53.7 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
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
export ZSH=$HOME/.zsh
export OS=`uname | tr "[:upper:]" "[:lower:]"`
# Set to this to use case-sensitive completion
export CASE_SENSITIVE="true"
# add a function path
fpath=($ZSH/functions $fpath)
# {{{ alias
# Push and pop directories on directory stack
alias pu='pushd'
alias po='popd'
# Basic directory operations
alias ...='cd ../..'
alias -- -='cd -'
# Super user
alias _='sudo'
#alias g='grep -in'
# Show history
alias history='fc -l 1'
# List direcory contents
alias lsa='ls -lah'
alias l='ls -la'
alias ll='ls -l'
alias sl=ls # often screw this up
alias afind='ack-grep -il'
alias dtrace-providers="sudo dtrace -l | perl -pe 's/^.*?\S+\s+(\S+?)([0-9]|\s).*/\1/' | sort | uniq"
alias tail_java_complete="tail -f $HOME/javacomplete.txt $HOME/dotfiles/.vim/bundle/javacomplete/java/javacomplete_java.log"
# }}}
# {{{
# ls colors
autoload colors; colors;
export LSCOLORS="Gxfxcxdxbxegedabagacad"
export LS_COLORS="*.tar.bz2=38;5;226:*.tar.xz=38;5;130:*PKGBUILD=48;5;233;38;5;160:*.html=38;5;213:*.htm=38;5;213:*.vim=38;5;142:*.css=38;5;209:*.screenrc=38;5;120:*.procmailrc=38;5;120:*.zshrc=38;5;120:*.bashrc=38;5;120:*.xinitrc=38;5;120:*.vimrc=38;5;120:*.htoprc=38;5;120:*.muttrc=38;5;120:*.gtkrc-2.0=38;5;120:*.fehrc=38;5;120:*.rc=38;5;120:*.md=38;5;130:*.markdown=38;5;130:*.conf=38;5;148:*.h=38;5;81:*.rb=38;5;192:*.c=38;5;110:*.diff=38;5;31:*.yml=38;5;208:*.pl=38;5;178:*.csv=38;5;136:tw=38;5;003:*.chm=38;5;144:*.bin=38;5;249:*.pdf=38;5;203:*.mpg=38;5;38:*.ts=38;5;39:*.sfv=38;5;191:*.m3u=38;5;172:*.txt=38;5;192:*.log=38;5;190:*.swp=38;5;241:*.swo=38;5;240:*.theme=38;5;109:*.zsh=38;5;173:*.nfo=38;5;113:mi=38;5;124:or=38;5;160:ex=38;5;197:ln=target:pi=38;5;130:ow=38;5;208:fi=38;5;007:so=38;5;167:di=38;5;30:*.pm=38;5;197:*.pl=38;5;166:*.sh=38;5;243:*.patch=38;5;37:*.tar=38;5;118:*.tar.gz=38;5;172:*.zip=38;5;11::*.rar=38;5;11:*.tgz=38;5;11:*.7z=38;5;11:*.mp3=38;5;173:*.flac=38;5;166:*.mkv=38;5;115:*.avi=38;5;114:*.wmv=38;5;113:*.jpg=38;5;66:*.jpeg=38;5;67:*.png=38;5;68:*.pacnew=38;5;33"
#export LS_COLORS
# Enable ls colors
if [ "$DISABLE_LS_COLORS" != "true" ]
then
# Find the option for using colors in ls, depending on the version: Linux or BSD
ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
fi
setopt no_beep
setopt auto_cd
setopt multios
setopt cdablevarS
if [[ x$WINDOW != x ]]
then
SCREEN_NO="%B$WINDOW%b "
else
SCREEN_NO=""
fi
# Apply theming defaults
PS1="%n@%m:%~%# "
# git theming default: Variables for theming the git info prompt
ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name
ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt
ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
# Setup the prompt with pretty colors
setopt prompt_subst
setopt transient_rprompt
# Load the theme
PROMPT=$'%{$fg_bold[yellow]%}[<%n@%{$fg_bold[green]%}%m%{$fg_bold[yellow]%}>]%{$reset_color%}%{$fg[white]%}[$fg_bold[yellow]${PWD/#$HOME/~}]%{$reset_color%}$(git_prompt_info)\
%{$fg_bold[yellow]%}$ %{$reset_color%}'
PROMPT2=$'%{$fg_bold[yellow]%}[<%n@%{$fg_bold[green]%}%m%{$fg_bold[yellow]%}>]%{$reset_color%}%{$fg[white]%}[$fg_bold[yellow]${PWD/#$HOME/~}]%{$reset_color%}$(git_prompt_info)\
%{$fg_bold[yellow]%}%_$ %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}*%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
function battery_charge {
echo `$HOME/bin/battery_charge` 2>/dev/null
}
setopt prompt_subst # Enables additional prompt extentions
autoload -U colors && colors # Enables colours
RPROMPT='[%(0?,,<%?> )][%F{cyan}%D{%e.%b.%y %H:%M:%S}%F{white}]'
# }}}
# {{{
# fixme - the load process here seems a bit bizarre
unsetopt menu_complete # do not autoselect the first completion entry
unsetopt flowcontrol
setopt auto_menu # show completion menu on succesive tab press
setopt complete_in_word
setopt always_to_end
setopt c_bases
setopt extended_glob
setopt no_match
setopt print_eight_bit
setopt no_correct
setopt complete_in_word
setopt list_packed # Compact completion lists
setopt list_types # Show types in completion
setopt rec_exact # Recognize exact, ambiguous matches
setopt short_loops
WORDCHARS=''
WORDCHARS=${WORDCHARS//[&=\/;\!#%\{]}
autoload -U compinit
compinit -i
zmodload -i zsh/complist
## case-insensitive (all),partial-word and then substring completion
if [ "x$CASE_SENSITIVE" = "xtrue" ]; then
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
unset CASE_SENSITIVE
else
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
fi
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' squeeze-slashes true
# should this be in keybindings?
bindkey -M menuselect '^o' accept-and-infer-next-history
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
zstyle ':completion:*:*:*:*:processes*' force-list always
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:kill:*:processes' sort false
zstyle ':completion:*:*:kill:*:processes' command 'ps -u "$USER"'
zstyle ':completion:*:*:killall:*:processes' command 'ps --forest -A -o pid,user,cmd'
zstyle ':completion:*:processes-names' command "ps axho cmd= | sed 's:\([^ ]*\).*:\1:;s:\(/[^ ]*/\)::;/^\[/d'"
zstyle ':completion:*:processes' command 'ps -au$USER -o pid,time,cmd|grep -v "ps -au$USER -o pid,time,cmd"'
zstyle ':completion:*:matches' group yes
zstyle ':completion:*:options' description yes
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:descriptions' format $'\e[01;33m-- %d --\e[0m'
zstyle ':completion:*:messages' format $'\e[01;35m-- %d --\e[0m'
zstyle ':completion:*:warnings' format $'\e[01;31m-- no matches found --\e[0m'
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.*' insert-sections true
zstyle ':completion:*:man:*' menu yes select
zstyle ':completion:*:rm:*' ignore-line yes
zstyle ':completion:*:cp:*' ignore-line yes
zstyle ':completion:*:mv:*' ignore-line yes
compdef _gnu_generic slrnpull make df du mv cp makepkg
# disable named-directories autocompletion
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
cdpath=(.)
# use /etc/hosts and known_hosts for hostname completion
[ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
[ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
hosts=(
"$_ssh_hosts[@]"
"$_etc_hosts[@]"
`hostname`
localhost
)
zstyle ':completion:*:hosts' hosts $hosts
# Use caching so that commands like apt and dpkg complete are useable
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.oh-my-zsh/cache/
# Don't complete uninteresting users
zstyle ':completion:*:*:*:users' ignored-patterns \
adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
mailman mailnull mldonkey mysql nagios \
named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
operator pcap postfix postgres privoxy pulse pvm quagga radvd \
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
# ... unless we really want to.
zstyle '*' single-ignored show
# }}}
# {{{
#setopt correct_all
#alias man='nocorrect man'
#alias mv='nocorrect mv'
#alias mysql='nocorrect mysql'
#alias mkdir='nocorrect mkdir'
#alias gist='nocorrect gist'
#alias heroku='nocorrect heroku'
#alias ebuild='nocorrect ebuild'
#alias hpodder='nocorrect hpodder'
# }}}
# {{{ filename completion
# Force file name completion on C-x TAB, Shift-TAB.
zle -C complete-files complete-word _generic
zstyle ':completion:complete-files:*' completer _files
bindkey "^Q" complete-files
bindkey "^[[Z" complete-files
# Force menu on C-x RET.
zle -C complete-first complete-word _generic
zstyle ':completion:complete-first:*' menu yes
bindkey "^W" complete-first
# }}}
# {{{
# Changing/making/removing directory
setopt auto_name_dirs
setopt auto_pushd
setopt pushd_ignore_dups
alias ..='cd ..'
alias cd..='cd ..'
alias cd...='cd ../..'
alias cd....='cd ../../..'
alias cd.....='cd ../../../..'
alias cd/='cd /'
alias 1='cd -'
alias 2='cd +2'
alias 3='cd +3'
alias 4='cd +4'
alias 5='cd +5'
alias 6='cd +6'
alias 7='cd +7'
alias 8='cd +8'
alias 9='cd +9'
cd () {
if [[ "x$*" == "x..." ]]; then
cd ../..
elif [[ "x$*" == "x...." ]]; then
cd ../../..
elif [[ "x$*" == "x....." ]]; then
cd ../../..
elif [[ "x$*" == "x......" ]]; then
cd ../../../..
else
builtin cd "$@"
fi
}
alias md='mkdir -p'
alias rd=rmdir
alias d='dirs -v'
# }}}
# {{{
## fixme, i duplicated this in xterms - oops
function title {
if [[ $TERM == "screen" ]]; then
# Use these two for GNU Screen:
print -nR $'\033k'$1$'\033'\\\
print -nR $'\033]0;'$2$'\a'
elif [[ ($TERM =~ "^xterm") ]] || [[ ($TERM == "rxvt") ]]; then
# Use this one instead for XTerms:
print -nR $'\033]0;'$*$'\a'
fi
}
function precmd {
title zsh "$PWD"
}
function preexec {
emulate -L zsh
local -a cmd; cmd=(${(z)1})
title $cmd[1]:t "$cmd[2,-1]"
}
function zsh_stats() {
history | awk '{print $2}' | sort | uniq -c | sort -rn | head
}
function uninstall_oh_my_zsh() {
/bin/sh $ZSH/tools/uninstall.sh
}
function upgrade_oh_my_zsh() {
/bin/sh $ZSH/tools/upgrade.sh
}
function take() {
mkdir -p $1
cd $1
}
# }}}
# {{{
# get the name of the branch we are on
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
parse_git_dirty () {
if [[ -n $(git status -s 2> /dev/null) ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
}
function tree() {
find . | sed -e 's/[^\/]*\//|--/g' -e 's/-- |/ |/g' | $PAGER
}
# get the status of the working tree
git_prompt_status() {
INDEX=$(git status --porcelain 2> /dev/null)
STATUS=""
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
fi
if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
fi
if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
fi
if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS"
fi
if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
fi
if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
fi
echo $STATUS
}
# }}}
#
# Color grep results
# Examples: http://rubyurl.com/ZXv
#
export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;32'
export GREP_COLORS="38;5;230:sl=38;5;240:cs=38;5;100:mt=38;5;161:fn=38;5;197:ln=38;5;212:bn=38;5;44:se=38;5;166"
# {{{
## Command history configuration
HISTFILE=$HOME/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt hist_find_no_dups # ignore duplication command history list
setopt hist_ignore_all_dups # ignore duplication command history list
setopt share_history # share command history data
setopt hist_verify
setopt inc_append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_space
setopt SHARE_HISTORY
setopt APPEND_HISTORY
# }}}
# {{{
# TODO: Explain what some of this does..
autoload -U compinit
compinit -i
bindkey -e
bindkey '\ew' kill-region
bindkey -s '\el' "ls\n"
bindkey -s '\e.' "..\n"
bindkey '^r' history-incremental-search-backward
bindkey "^[[5~" up-line-or-history
bindkey "^[[6~" down-line-or-history
# make search up and down work, so partially type and hit up/down to find relevant stuff
bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search
bindkey "^[[7~" beginning-of-line # Home
bindkey "^[[8~" end-of-line # End
bindkey "^[[H" beginning-of-line
bindkey "^[[1~" beginning-of-line
bindkey "^[[F" end-of-line
bindkey "^[[4~" end-of-line
bindkey ' ' magic-space # also do history expansion on space
bindkey '^[[Z' reverse-menu-complete
bindkey "\e[1;3D" backward-word
bindkey "\e[1;3C" forward-word
bindkey "\e3D" backward-word
bindkey "\e3C" forward-word
bindkey '^[5D' backward-word
bindkey '^[5C' forward-word
bindkey '^[[5D' backward-word
bindkey '^[[5C' forward-word
bindkey '^[[3~' delete-char
# Move to where the arguments belong.
after-first-word() {
zle beginning-of-line
zle forward-word
}
zle -N after-first-word
bindkey "^X1" after-first-word
# }}}
# {{{
## smart urls
autoload -U url-quote-magic
zle -N self-insert url-quote-magic
## file rename magick
bindkey "^[m" copy-prev-shell-word
## jobs
setopt long_list_jobs
## pager
export PAGER=less
# }}}
# {{{
#! /bin/zsh
# A script to make using 256 colors in zsh less painful.
# P.C. Shyamshankar <[email protected]>
# Copied from http://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
typeset -Ag FX FG BG
FX=(
reset "%{[00m%}"
bold "%{[01m%}" no-bold "%{[22m%}"
italic "%{[03m%}" no-italic "%{[23m%}"
underline "%{[04m%}" no-underline "%{[24m%}"
blink "%{[05m%}" no-blink "%{[25m%}"
reverse "%{[07m%}" no-reverse "%{[27m%}"
)
for color in {000..255}; do
FG[$color]="%{[38;5;${color}m%}"
BG[$color]="%{[48;5;${color}m%}"
done
# }}}
# {{{
case "$TERM" in
xterm*|rxvt*)
preexec () {
print -Pn "\e]0;%n@%m: $1\a" # xterm
}
precmd () {
print -Pn "\e]0;%n@%m: %~\a" # xterm
}
;;
screen*)
preexec () {
local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]}
echo -ne "\ek$CMD\e\\"
print -Pn "\e]0;%n@%m: $1\a" # xterm
}
precmd () {
echo -ne "\ekzsh\e\\"
print -Pn "\e]0;%n@%m: %~\a" # xterm
}
;;
esac
# }}}
# {{{
# Color grep results
# Examples: http://rubyurl.com/ZXv
#
export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;32'
# }}}
# {{{
## Command history configuration
HISTFILE=$HOME/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt hist_find_no_dups # ignore duplication command history list
setopt hist_ignore_all_dups # ignore duplication command history list
setopt share_history # share command history data
setopt hist_verify
setopt inc_append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_space
setopt SHARE_HISTORY
setopt APPEND_HISTORY
# }}}
#{{{
# Aliases
alias g='git'
alias gst='git status'
alias gl='git pull'
alias gup='git fetch && git rebase'
alias gp='git push'
alias gd='git diff | mate'
alias gdv='git diff -w "$@" | vim -R -'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gcount='git shortlog -sn'
alias gcp='git cherry-pick'
alias glg='git log --stat --max-count=5'
# Git and svn mix
alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
#
# Will return the current branch name
# Usage example: git pull origin $(current_branch)
#
function current_branch() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
# these aliases take advangate of the previous function
alias ggpull='git pull origin $(current_branch)'
alias ggpush='git push origin $(current_branch)'
alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
#}}}
fpath=($HOME/.zsh/ $fpath)
autoload -Uz compinit
compinit -i
# functions {{{
function cl() { cd "$@" && l; }
function cs () {
cd "$@"
if [ -n "$(git status 2>/dev/null)" ]; then
echo "$(git status 2>/dev/null)"
fi
}
function mkd() {
mkdir -p "$*" && cd "$*" && pwd
}
function gco {
if [ -z "$1" ]; then
git checkout master
else
git checkout $1
fi
}
# autojump
j() {
# change jfile if you already have a .j file for something else
local jfile=$HOME/.j
if [ "$1" = "--add" ]; then
shift
# we're in $HOME all the time, let something else get all the good letters
[ "$*" = "$HOME" ] && return
awk -v q="$*" -F"|" '
$2 >= 1 {
if( $1 == q ) { l[$1] = $2 + 1; found = 1 } else l[$1] = $2
count += $2
}
END {
found || l[q] = 1
if( count > 1000 ) {
for( i in l ) print i "|" 0.9*l[i] # aging
} else for( i in l ) print i "|" l[i]
}
' $jfile 2>/dev/null > $jfile.tmp
mv -f $jfile.tmp $jfile
elif [ "$1" = "" -o "$1" = "--l" ];then
shift
awk -v q="$*" -F"|" '
BEGIN { split(q,a," ") }
{ for( i in a ) $1 !~ a[i] && $1 = ""; if( $1 ) print $2 "\t" $1 }
' $jfile 2>/dev/null | sort -n
# for completion
elif [ "$1" = "--complete" ];then
awk -v q="$2" -F"|" '
BEGIN { split(substr(q,3),a," ") }
{ for( i in a ) $1 !~ a[i] && $1 = ""; if( $1 ) print $1 }
' $jfile 2>/dev/null
# if we hit enter on a completion just go there (ugh, this is ugly)
elif [[ "$*" =~ "/" ]]; then
local x=$*; x=/${x#*/}; [ -d "$x" ] && cd "$x"
else
# prefer case sensitive
local cd=$(awk -v q="$*" -F"|" '
BEGIN { split(q,a," ") }
{ for( i in a ) $1 !~ a[i] && $1 = ""; if( $1 ) { print $2 "\t" $1; x = 1 } }
END {
if( x ) exit
close(FILENAME)
while( getline < FILENAME ) {
for( i in a ) tolower($1) !~ tolower(a[i]) && $1 = ""
if( $1 ) print $2 "\t" $1
}
}
' $jfile 2>/dev/null | sort -nr | head -n 1 | cut -f 2)
[ "$cd" ] && cd "$cd"
fi
}
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
# hack & ship
function current_git_branch {
git branch 2> /dev/null | grep '\*' | awk '{print $2}'
}
hack()
{
CURRENT=$(current_git_branch)
git checkout master
git pull origin master
git checkout ${CURRENT}
git rebase master
unset CURRENT
}
ship()
{
CURRENT=$(current_git_branch)
git checkout master
git merge ${CURRENT}
git push origin master
git checkout ${CURRENT}
unset CURRENT
}
git-pull-rebase () {
git fetch origin
git rebase -p origin/master
}
function pswhich {
for i in $*; do
grepstr=[${i[1,2]}]${i[2,${#i}]}
tmp=`ps axwww | grep $grepstr | awk '{print $1}'`
echo "${i}: ${tmp/\\n/,}"
done
}
function cdgem {
cd /opt/local/lib/ruby/gems/1.8/gems/; cd `ls|grep $1|sort|tail -1`
}
function cdpython {
cd /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/;
}
function mycd {
MYCD=/tmp/mycd.txt
touch ${MYCD}
typeset -i x
typeset -i ITEM_NO
typeset -i i
x=0
if [[ -n "${1}" ]]; then
if [[ -d "${1}" ]]; then
print "${1}" >> ${MYCD}
sort -u ${MYCD} > ${MYCD}.tmp
mv ${MYCD}.tmp ${MYCD}
FOLDER=${1}
else
i=${1}
FOLDER=$(sed -n "${i}p" ${MYCD})
fi
fi
if [[ -z "${1}" ]]; then
print ""
cat ${MYCD} | while read f; do
x=$(expr ${x} + 1)
print "${x}. ${f}"
done
print "\nSelect #"
read ITEM_NO
FOLDER=$(sed -n "${ITEM_NO}p" ${MYCD})
fi
if [[ -d "${FOLDER}" ]]; then
cd ${FOLDER}
fi
}
# mkdir, cd into it
mkcd () {
mkdir -p "$*"
cd "$*"
}
calc () { echo "$*" | bc -l; }
# }}}
# program settings & paths {{{
export SCONS_LIB_DIR="/Library/Python/2.6/site-packages/scons-1.2.0-py2.6.egg/scons-1.2.0"
export COPY_EXTENDED_ATTRIBUTES_DISABLE=true
# flex & air
export FLEX_HOME=$HOME/work/tools/air-sdk-4.5.0
export FLEX_SDK=$FLEX_HOME
export FLEX_SDK_HOME=$FLEX_HOME
export AIR_SDK=$FLEX_HOME
export AIR_SDK_HOME=$FLEX_HOME
# tamarin, asc and friends
export TAMARIN_HOME=$HOME/temp/svn_other_projects/lang.tamarin-central
export ASC=$HOME/temp/svn_other_projects/flexsdk/lib/asc.jar
export ASC_COMMAND="java -ea -DAS3 -DAVMPLUS -classpath ${ASC} macromedia.asc.embedding.ScriptCompiler -abcfuture "
export AVMSHELL_COMMAND=$HOME/temp/svn_other_projects/lang.tamarin-central/__build/shell/avmshell
export AVMSHELL_DEBUG_COMMAND=$HOME/temp/svn_other_projects/lang.tamarin-central/__build_debugger/shell/avmshell
# python
export PYTHONPATH=/opt/local/lib/python2.5/site-packages:$HOME/.python
export PYTHONPATH=$PYTHONPATH:$HOME/.python
export PYTHONSTARTUP=$HOME/.pythonstartup
#ant
export ANT_HOME=$HOME/work/tools/apache-ant-1.8.2
export ANT_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=512m -XX:PermSize=256m"
# maven
#export M2=$HOME/work/apache-maven-3.0.3/bin/
#export M2_HOME=$HOME/work/apache-maven-3.0.3/
export MAVEN_REPO=$HOME/.m2/repository
#export LESS='-fXemPm?f%f .?lbLine %lb?L of %L..:$' # Set options for less command
export LESS="-rX"
export PAGER=less
if [ "`uname`" = "Darwin" ]; then
export EDITOR=$HOME/Applications/MacVim.App/Contents/MacOS/Vim
export GIT_EDITOR=$HOME/Applications/MacVim.App/Contents/MacOS/Vim
else
export EDITOR=/usr/bin/vim
export GIT_EDITOR=/usr/bin/vim
fi
export VISUAL='vim'
export INPUTRC=~/.inputrc
export LANG="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_NUMERIC="en_US.utf8"
export LC_TIME="en_US.utf8"
export LC_COLLATE="en_US.utf8"
export LC_MONETARY="en_US.utf8"
export LC_MESSAGES="en_US.utf8"
export LC_PAPER="en_US.utf8"
export LC_NAME="en_US.utf8"
export LC_ADDRESS="en_US.utf8"
export LC_TELEPHONE="en_US.utf8"
export LC_MEASUREMENT="en_US.utf8"
export LC_IDENTIFICATION="en_US.utf8"
export LC_ALL=""
export VERSIONER_PERL_PREFER_32_BIT=yes
export PERL_BADLANG=0
if [ $OS == "linux" ];
then
export PERL_LOCAL_LIB_ROOT=$HOME/.perl5
export PERL_MB_OPT="--install_base $HOME/.perl5";
export PERL_MM_OPT="INSTALL_BASE=$HOME/.perl5";
export PERL5LIB="$HOME/.perl5/lib/perl5/x86_64-linux-gnu-thread-multi:$HOME/.perl5/lib/perl5";
export PATH="$HOME/.perl5/bin:$PATH";
fi
export DISPLAY=:0.0
# hla
export hlalib=/usr/hla/hlalib
export hlainc=/usr/hla/include
# colors in terminal
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
#GO
export GOROOT=$HOME/temp/svn_other_projects/go
export GOOS=$OS
export GOARCH=amd64
export GOBIN=$HOME/bin/$OS/go
export P4CONFIG=.p4conf
export HTML_TIDY=$HOME/.tidyconf
export FCSH_VIM_ROOT=$HOME/work/flex/sdk/bin
export WIKI=$HOME/Documents/personal/life/exploded/
export JAQL_HOME=$HOME/work/saasbase_env/jaql
export HADOOP_HOME=$HOME/work/saasbase_env/hadoop
export HBASE_HOME=$HOME/work/saasbase_env/hbase
export ZOOKEEPER_HOME=$HOME/work/saasbase_env/zookeeper
export STORM_HOME=$HOME/work/saasbase_env/storm
# saasbase
export SAASBASE_DB_HOME=$HOME/work/saasbase_env/src/saasbase_db
export SAASBASE_ANALYTICS_HOME=$HOME/work/saasbase_env/src/saasbase_analytics
export SAASBASE_DATAROOT=/var
export ROO_HOME=$HOME/work/tools/spring-roo-1.1.0.M1
export MONO_GAC_PREFIX=/usr/local
# luatext
#export TEXMFCNF=/usr/local/texlive/2008/texmf/web2c/
#export LUAINPUTS='{/usr/local/texlive/texmf-local/tex/context/base,/usr/local/texlive/texmf-local/scripts/context/lua,$HOME/texmf/scripts/context/lua}'
#export TEXMF='{$HOME/.texlive2008/texmf-config,$HOME/.texlive2008/texmf-var,$HOME/texmf,/usr/local/texlive/2008/texmf-config,/usr/local/texlive/2008/texmf-var,/usr/local/texlive/2008/texmf,/usr/local/texlive/texmf-local,/usr/local/texlive/2008/texmf-dist,/usr/local/texlive/2008/texmf.gwtex}'
export TEXMFCACHE=/tmp
#export TEXMFCNF=/usr/local/texlive/2008/texmf/web2c
# java
if [ "`uname`" = "Darwin" ]; then
export JAVA_HOME=/Library/Java/JavaVirtualMachines/1.6.0_27-b07-395.jdk/Contents/Home/
else
export JAVA_HOME=/usr/lib/jvm/java-6-sun/
fi
#export JUNIT_HOME=/usr/share/junit
# haxe
#export HAXE_LIBRARY_PATH=/usr/local/haxe/std:.
#export NEKOPATH=/usr/local/neko
export NOTES=$HOME/Documents/personal/life/notes@/
if [ "`uname`" = "Darwin" ]; then
export VIMRUNTIME=$HOME/Applications/MacVim.app/Contents/Resources/vim/runtime/
fi
export SCALA_HOME=$HOME/work/tools/scala-2.9.1
# }}}
# path {{{
export PATH=\
/usr/local/bin:\
/usr/local/sbin:\
/usr/local/php5/bin:\
$HOME/bin:\
$HOME/bin/$OS:\
"/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin":\
"$HOME/Applications/Graphics/Graphviz.app/Contents/MacOS":\
/usr/local/lib/ocaml_godi/bin/:\
$HOME/.cabal/bin/:\
$HOME/temp/svn_other_projects/sshuttle/:\
$FLEX_HOME/bin:\
/opt/local/bin:\
/opt/local/sbin:\
/usr/local/mysql/bin:\
$HOME/Applications/zero-1.0.0.P20070702-1062:\
$HOME/temp/svn_other_projects/factor:\
$HOME/work/tools/emulator/Vice/tools:\
$HOME/work/tools/gradle-1.0-milestone-1/bin/:\
$HOME/work/tools/rhino1_7R2/:\
$HOME/work/tools/nasm/:\
$HOME/temp/svn_other_projects/rock/bin:\
$HOME/.cljr/bin:\
$ROO_HOME/bin:\
$HOME/Applications/emulator/n64/mupen64plus-1.99.4-osx/x86_64/:\
"$HOME/Applications/Racket v5.0.2/bin/":\
$HOME/work/tools/android-sdk-mac_x86/tools/:\
$HOME/work/tools/android-sdk-mac_x86/platform-tools/:\
$HOME/work/tools/whirr-0.3.0-CDH3B4/bin/:\
$HOME/work/tools/elastic-mapreduce/:\
$HOME/work/tools/leiningen/:\
$PATH:/usr/hla:\
$SCALA_HOME/bin/:\
$HOME/work/tools/play-2.0-beta/:\
/usr/local/Ice/bin:\
$HOME/work/tools/apache-ant-1.8.2/bin:\
$HOME/work/tools/apache-maven-3.0.3/bin:\
$GOBIN:\
$PATH
if [ "`uname`" = "Darwin" ]; then
export PATH=$PATH:\
$HOME/bin/$OS:\
$HOME/bin/$OS/clic
fi
export MANPATH=\
/opt/loca/share/man:\
/usr/local/man:\
$MANPATH
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:\
/usr/local/spidermonkey/lib
export DYLD_FRAMEWORK_PATH=$DYLD_FRAMEWORK_PATH:\
"$HOME/Applications/Racket v5.0.1/lib/"
# }}}
# aliases {{{
# common
#alias ack="ack -i -a"
alias vidir="EDITOR=v vidir"
alias gvim="g"
alias c="clear"
alias l="ls -AGlFT"
alias lt="ls -AGlFTtr"
alias gwhat="grep -e $1"
# pssh
alias pssh_mia='pssh -P -l admin -h ~/.pssh/hosts_saasbase_miami'
alias pssh_rtc='pssh -P -l hadoop -h ~/.pssh/hosts_rtc'
alias pscp_rtc='pscp -l hadoop -h ~/.pssh/hosts_rtc'
alias pssh_rtc='pssh -P -l admin -h ~/.pssh/hosts_staging_css'
alias pscp_rtc='pscp -l admin -h ~/.pssh/hosts_staging_css'
# bochs
alias bochs='LTDL_LIBRARY_PATH=$HOME/work/tools/bochs/lib/bochs/plugins BXSHARE=$HOME/work/tools/bochs/share/bochs $HOME/work/tools/bochs/bin/bochs'
#editor
case "$HOST" in