zshrc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. #
  2. # .zshrc is sourced in interactive shells.
  3. # It should contain commands to set up aliases,
  4. # functions, options, key bindings, etc.
  5. #
  6. ##################
  7. # LOAD FUNCTIONS #
  8. ##################
  9. ## completions
  10. autoload -U compinit
  11. compinit
  12. ## colors
  13. autoload -U colors
  14. colors
  15. ## renaming
  16. autoload zmv
  17. alias mmv='noglob zmv -W'
  18. ###############
  19. # SET OPTIONS #
  20. ###############
  21. # vi keybindings
  22. bindkey -v
  23. #allow tab completion in the middle of a word
  24. setopt COMPLETE_IN_WORD
  25. ## Correct my spelling
  26. #setopt CORRECT
  27. ## Don't ask me
  28. setopt RMSTARSILENT
  29. ## Don't require 'cd'
  30. #setopt AUTOCD
  31. ## Automatically pushd - then I can go to an old dir with cd - <tab> (pick no.)
  32. setopt AUTOPUSHD
  33. export DIRSTACKSIZE=11 # stack size of eleven gives me a list with ten entries
  34. ## Autocomplete hosts from .ssh/known_hosts
  35. #local _myhosts
  36. _myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} )
  37. zstyle ':completion:*' hosts $_myhosts
  38. HISTSIZE=3000
  39. SAVEHIST=3000
  40. HISTFILE=~/.zsh_history
  41. #####################
  42. # SHELL ENVIRONMENT #
  43. #####################
  44. ## Ctrl-W stops at a directory
  45. ## see http://www.zsh.org/mla/users/1995/msg00088.html
  46. WORDCHARS='*?_-.[]~\!#$%^(){}<>|`@#$%^*()+:?'
  47. ## set up my prompt
  48. export PS1="%{${fg[yellow]}%}[%n@%m] %{${fg[green]}%}%3~ %# %{${fg[default]}%}"
  49. #export RPS1="%{${fg[yellow]}%}%T%{${fg[default]}%}"
  50. ## color STDERR red
  51. #exec 2>>(while read line; do
  52. # print '\e[91m'${(q)line}'\e[0m' > /dev/tty; done &)
  53. #if [ "`uname`" = "Darwin" ]; then
  54. # compctl -f -x 'c[-1,-a][-1,-A] p[2]' -s "`/bin/ls -d1 /Applications/*/*.app /Applications/*.app | sed 's|^.*/\([^/]*\)\.app.*|\\1|;s/ /\\\\ /g'`" -- open
  55. # alias run='open -a'
  56. #fi
  57. ## set list colours
  58. export LS_COLORS='no=00:fi=00:di=00;36:ln=01;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:'
  59. #############
  60. # SSH AGENT #
  61. #############
  62. # Don't do for OSX, as it has it's own handling of ssh-agent
  63. if [ `uname` != Darwin ]; then
  64. # Check to see if SSH Agent is already running
  65. agent_pid="$(ps -ef | grep "ssh-agent" | grep -v "grep" | awk '{print($2)}')"
  66. # If the agent is not running (pid is zero length string)
  67. if [[ -z "$agent_pid" ]]; then
  68. # Start up SSH Agent
  69. # this seems to be the proper method as opposed to `exec ssh-agent bash`
  70. eval "$(ssh-agent)"
  71. # if you have a passphrase on your key file you may or may
  72. # not want to add it when logging in, so comment this out
  73. # if asking for the passphrase annoys you
  74. #ssh-add
  75. # If the agent is running (pid is non zero)
  76. else
  77. # Connect to the currently running ssh-agent
  78. # this doesn't work because for some reason the ppid is 1 both when
  79. # starting from ~/.profile and when executing as `ssh-agent bash`
  80. #agent_ppid="$(ps -ef | grep "ssh-agent" | grep -v "grep" | awk '{print($3)}')"
  81. agent_ppid="$(($agent_pid - 1))"
  82. # and the actual auth socket file name is simply numerically one less than
  83. # the actual process id, regardless of what `ps -ef` reports as the ppid
  84. agent_sock="$(find /tmp -path "*ssh*" -type s -iname "agent.$agent_ppid")"
  85. echo "Agent pid $agent_pid"
  86. export SSH_AGENT_PID="$agent_pid"
  87. echo "Agent sock $agent_sock"
  88. export SSH_AUTH_SOCK="$agent_sock"
  89. fi
  90. fi
  91. #############
  92. # FUNCTIONS #
  93. #############
  94. trash() { mv $@ ~/.Trash }
  95. pc() { awk "{print \$$1}" }
  96. mcd() { mkdir -p "$1" && cd "$1" }
  97. calc() { echo "$@" | bc -l -q -i }
  98. dont() { echo "OK, I won't!" }
  99. settab() { echo -ne "\e]1;$1\a" }
  100. settabh() { settab `hostname | cut -d. -f1` }
  101. #'"
  102. ###########
  103. # ALIASES #
  104. ###########
  105. ## history
  106. alias h='history'
  107. ## shortcuts
  108. alias l='ls'
  109. alias l1='ls -1'
  110. alias ll='ls -hl'
  111. alias la='ls -A'
  112. alias lal="ls -Ahl"
  113. alias l.='ls -d .[^.]*'
  114. alias lsd='ls -ld *(-/DN)'
  115. alias lg='ls -l | grep -i'
  116. alias cd..='cd ..';
  117. alias ..='cd ..'
  118. alias df='df -h'
  119. alias du='du -sh'
  120. alias mkdir='nocorrect mkdir'
  121. alias mv='nocorrect mv'
  122. alias cp='nocorrect cp'
  123. alias touch='nocorrect touch'
  124. alias ln='nocorrect ln'
  125. alias -g G="| grep"
  126. alias -g g="| grep -i"
  127. alias -g L="| less"
  128. alias -g H="| head"
  129. alias -g ...="../.."
  130. alias -g ....="../../.."
  131. alias -g .....="../../../.."
  132. alias igrep='grep -i'
  133. alias rgrep='grep -R'
  134. alias rigrep='grep -iR'
  135. alias proxy='export http_proxy=http://192.168.1.248:3128;export HTTP_PROXY=$http_proxy;export https_proxy=$http_proxy;export HTTPS_PROXY=$http_proxy;export ftp_proxy=$http_proxy;export FTP_PROXY=$http_proxy;'
  136. alias noproxy='export http_proxy='';export HTTP_PROXY=$http_proxy;export https_proxy=$http_proxy;export HTTPS_PROXY=$http_proxy;export ftp_proxy=$http_proxy;export FTP_PROXY=$http_proxy;'
  137. alias hosts='vim /etc/hosts'
  138. alias graceful='apachectl graceful'
  139. alias flushdns='lookupd -flushcache'
  140. alias bc='bc -l'
  141. alias o.='open .'
  142. alias upd='cvs -q upd -dP'
  143. alias upd-head='cvs -q upd -dPA'
  144. #alias guantanamo-start='env -i /usr/sbin/chroot /jails/guantanamo /usr/local/apache2/bin/httpd -k start'
  145. #alias guantanamo-graceful='env -i /usr/sbin/chroot /jails/guantanamo /usr/local/apache2/bin/httpd -k graceful'
  146. #alias guantanamo-stop='env -i /usr/sbin/chroot /jails/guantanamo /usr/local/apache2/bin/httpd -k stop'
  147. #alias guantanamo-check='chroot /jails/guantanamo /usr/local/apache2/bin/apachectl -t'
  148. #alias woomera-start='env -i /usr/sbin/chroot /jails/woomera /usr/local/apache2/bin/httpd -k start'
  149. #alias woomera-graceful='env -i /usr/sbin/chroot /jails/woomera /usr/local/apache2/bin/httpd -k graceful'
  150. #alias woomera-stop='env -i /usr/sbin/chroot /jails/woomera /usr/local/apache2/bin/httpd -k stop'
  151. #alias woomera-check='chroot /jails/woomera /usr/local/apache2/bin/apachectl -t'
  152. #alias littlehey-start='env -i /usr/sbin/chroot /jails/littlehey /usr/local/apache2/bin/httpd -k start'
  153. #alias littlehey-graceful='env -i /usr/sbin/chroot /jails/littlehey /usr/local/apache2/bin/httpd -k graceful'
  154. #alias littlehey-stop='env -i /usr/sbin/chroot /jails/littlehey /usr/local/apache2/bin/httpd -k stop'
  155. #alias littlehey-check='chroot /jails/littlehey /usr/local/apache2/bin/apachectl -t'
  156. #alias alcatraz-start='env -i /usr/sbin/chroot /jails/alcatraz /usr/local/apache2/bin/httpd -k start'
  157. #alias alcatraz-graceful='env -i /usr/sbin/chroot /jails/alcatraz /usr/local/apache2/bin/httpd -k graceful'
  158. #alias alcatraz-stop='env -i /usr/sbin/chroot /jails/alcatraz /usr/local/apache2/bin/httpd -k stop'
  159. #alias alcatraz-check='chroot /jails/alcatraz /usr/local/apache2/bin/apachectl -t'
  160. #alias kerobokan-start='env -i /usr/sbin/chroot /jails/kerobokan /usr/local/apache2/bin/httpd -k start'
  161. #alias kerobokan-graceful='env -i /usr/sbin/chroot /jails/kerobokan /usr/local/apache2/bin/httpd -k graceful'
  162. #alias kerobokan-stop='env -i /usr/sbin/chroot /jails/kerobokan /usr/local/apache2/bin/httpd -k stop'
  163. #alias kerobokan-check='chroot /jails/kerobokan /usr/local/apache2/bin/apachectl -t'
  164. #alias changi-start='/etc/init.d/tc-chroot start'
  165. #alias changi-stop='/etc/init.d/tc-chroot stop'
  166. # If I am on the mac,
  167. if [ `uname` = Darwin ]; then
  168. alias updatedb='sudo /usr/libexec/locate.updatedb'
  169. fi
  170. ## common typos
  171. #alias sl='ls' #commented out because Jaf's steam train /usr/bin/sl much more fun
  172. alias vf='cd'
  173. alias xs='cd'
  174. alias ks='ls'
  175. alias ecgi='echo'
  176. ## ensure X11 is running when I gvim, xterm etc
  177. alias xterm='open -a X11 && /usr/X11R6/bin/xterm -sb -sl 5000 -rightbar -fg white -bg black -geometry 100x50+40+20'
  178. alias gvim='open -a X11 && vim -g'
  179. ## on the other hand, don't try and connect to X when I am not gvimming
  180. #alias vim='vim -X'
  181. #alias x='open -a X11'
  182. settabh
  183. ## shortcuts to other machines
  184. alias murray='ssh weiyi@murray'
  185. alias nile='ssh weiyi@nile'
  186. alias niles='ssh weiyi@nile-stage'
  187. alias orinoco='ssh weiyi@orinoco'
  188. alias orinocos='ssh weiyi@orinoco-stage'
  189. alias kwai='ssh weiyi@kwai'
  190. alias devbox='ssh root@devbox'
  191. alias dev5='ssh root@dev5'
  192. alias danshui='ssh weiyi@danshui'
  193. alias elrond='ssh weiyi@elrond'
  194. alias samwise='ssh weiyi@samwise'
  195. alias tfine='ssh cinaeco@tfine'
  196. alias blackomelette='ssh cinaeco@10.0.1.1'
  197. ## shortcuts for development
  198. alias migrate='li3 migration db:migrate'
  199. alias oars-log='tail -F /jails/alcatraz/usr/local/www-conf/logs/oars-phplog'
  200. alias schools-log='tail -F /jails/alcatraz/usr/local/www-conf/logs/schools-phplog'
  201. alias delivery-log='tail -F /jails/alcatraz/usr/local/www-conf/logs/delivery-phplog'
  202. alias cdo='cd /jails/alcatraz/usr/local/www/oars'
  203. alias cds='cd /jails/alcatraz/usr/local/www/schools'
  204. alias cdd='cd /jails/alcatraz/usr/local/www/delivery'
  205. alias sqlo='mysql -u oars -p'