zshrc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. # Check to see if SSH Agent is already running
  63. agent_pid="$(ps -ef | grep "ssh-agent" | grep -v "grep" | awk '{print($2)}')"
  64. # If the agent is not running (pid is zero length string)
  65. if [[ -z "$agent_pid" ]]; then
  66. # Start up SSH Agent
  67. # this seems to be the proper method as opposed to `exec ssh-agent bash`
  68. eval "$(ssh-agent)"
  69. # if you have a passphrase on your key file you may or may
  70. # not want to add it when logging in, so comment this out
  71. # if asking for the passphrase annoys you
  72. #ssh-add
  73. # If the agent is running (pid is non zero)
  74. else
  75. # Connect to the currently running ssh-agent
  76. # this doesn't work because for some reason the ppid is 1 both when
  77. # starting from ~/.profile and when executing as `ssh-agent bash`
  78. #agent_ppid="$(ps -ef | grep "ssh-agent" | grep -v "grep" | awk '{print($3)}')"
  79. agent_ppid="$(($agent_pid - 1))"
  80. # and the actual auth socket file name is simply numerically one less than
  81. # the actual process id, regardless of what `ps -ef` reports as the ppid
  82. agent_sock="$(find /tmp -path "*ssh*" -type s -iname "agent.$agent_ppid")"
  83. echo "Agent pid $agent_pid"
  84. export SSH_AGENT_PID="$agent_pid"
  85. echo "Agent sock $agent_sock"
  86. export SSH_AUTH_SOCK="$agent_sock"
  87. fi
  88. #############
  89. # FUNCTIONS #
  90. #############
  91. trash() { mv $@ ~/.Trash }
  92. pc() { awk "{print \$$1}" }
  93. mcd() { mkdir -p "$1" && cd "$1" }
  94. calc() { echo "$@" | bc -l -q -i }
  95. dont() { echo "OK, I won't!" }
  96. settab() { echo -ne "\e]1;$1\a" }
  97. settabh() { settab `hostname | cut -d. -f1` }
  98. #'"
  99. ###########
  100. # ALIASES #
  101. ###########
  102. ## history
  103. alias h='history'
  104. ## shortcuts
  105. alias l='ls'
  106. alias l1='ls -1'
  107. alias ll='ls -hl'
  108. alias la='ls -A'
  109. alias lal="ls -Ahl"
  110. alias l.='ls -d .[^.]*'
  111. alias lsd='ls -ld *(-/DN)'
  112. alias lg='ls -l | grep -i'
  113. alias cd..='cd ..';
  114. alias ..='cd ..'
  115. alias df='df -h'
  116. alias du='du -sh'
  117. alias mkdir='nocorrect mkdir'
  118. alias mv='nocorrect mv'
  119. alias cp='nocorrect cp'
  120. alias touch='nocorrect touch'
  121. alias ln='nocorrect ln'
  122. alias -g G="| grep"
  123. alias -g g="| grep -i"
  124. alias -g L="| less"
  125. alias -g H="| head"
  126. alias -g ...="../.."
  127. alias -g ....="../../.."
  128. alias -g .....="../../../.."
  129. alias igrep='grep -i'
  130. alias rgrep='grep -R'
  131. alias rigrep='grep -iR'
  132. 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;'
  133. 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;'
  134. alias hosts='vim /etc/hosts'
  135. alias graceful='apachectl graceful'
  136. alias flushdns='lookupd -flushcache'
  137. alias bc='bc -l'
  138. alias o.='open .'
  139. alias upd='cvs -q upd -dP'
  140. alias upd-head='cvs -q upd -dPA'
  141. #alias guantanamo-start='env -i /usr/sbin/chroot /jails/guantanamo /usr/local/apache2/bin/httpd -k start'
  142. #alias guantanamo-graceful='env -i /usr/sbin/chroot /jails/guantanamo /usr/local/apache2/bin/httpd -k graceful'
  143. #alias guantanamo-stop='env -i /usr/sbin/chroot /jails/guantanamo /usr/local/apache2/bin/httpd -k stop'
  144. #alias guantanamo-check='chroot /jails/guantanamo /usr/local/apache2/bin/apachectl -t'
  145. #alias woomera-start='env -i /usr/sbin/chroot /jails/woomera /usr/local/apache2/bin/httpd -k start'
  146. #alias woomera-graceful='env -i /usr/sbin/chroot /jails/woomera /usr/local/apache2/bin/httpd -k graceful'
  147. #alias woomera-stop='env -i /usr/sbin/chroot /jails/woomera /usr/local/apache2/bin/httpd -k stop'
  148. #alias woomera-check='chroot /jails/woomera /usr/local/apache2/bin/apachectl -t'
  149. #alias littlehey-start='env -i /usr/sbin/chroot /jails/littlehey /usr/local/apache2/bin/httpd -k start'
  150. #alias littlehey-graceful='env -i /usr/sbin/chroot /jails/littlehey /usr/local/apache2/bin/httpd -k graceful'
  151. #alias littlehey-stop='env -i /usr/sbin/chroot /jails/littlehey /usr/local/apache2/bin/httpd -k stop'
  152. #alias littlehey-check='chroot /jails/littlehey /usr/local/apache2/bin/apachectl -t'
  153. #alias alcatraz-start='env -i /usr/sbin/chroot /jails/alcatraz /usr/local/apache2/bin/httpd -k start'
  154. #alias alcatraz-graceful='env -i /usr/sbin/chroot /jails/alcatraz /usr/local/apache2/bin/httpd -k graceful'
  155. #alias alcatraz-stop='env -i /usr/sbin/chroot /jails/alcatraz /usr/local/apache2/bin/httpd -k stop'
  156. #alias alcatraz-check='chroot /jails/alcatraz /usr/local/apache2/bin/apachectl -t'
  157. #alias kerobokan-start='env -i /usr/sbin/chroot /jails/kerobokan /usr/local/apache2/bin/httpd -k start'
  158. #alias kerobokan-graceful='env -i /usr/sbin/chroot /jails/kerobokan /usr/local/apache2/bin/httpd -k graceful'
  159. #alias kerobokan-stop='env -i /usr/sbin/chroot /jails/kerobokan /usr/local/apache2/bin/httpd -k stop'
  160. #alias kerobokan-check='chroot /jails/kerobokan /usr/local/apache2/bin/apachectl -t'
  161. #alias changi-start='/etc/init.d/tc-chroot start'
  162. #alias changi-stop='/etc/init.d/tc-chroot stop'
  163. # If I am on the mac,
  164. if [ `uname` = Darwin ]; then
  165. alias updatedb='sudo /usr/libexec/locate.updatedb'
  166. fi
  167. ## common typos
  168. #alias sl='ls' #commented out because Jaf's steam train /usr/bin/sl much more fun
  169. alias vf='cd'
  170. alias xs='cd'
  171. alias ks='ls'
  172. alias ecgi='echo'
  173. ## ensure X11 is running when I gvim, xterm etc
  174. alias xterm='open -a X11 && /usr/X11R6/bin/xterm -sb -sl 5000 -rightbar -fg white -bg black -geometry 100x50+40+20'
  175. alias gvim='open -a X11 && vim -g'
  176. ## on the other hand, don't try and connect to X when I am not gvimming
  177. #alias vim='vim -X'
  178. #alias x='open -a X11'
  179. settabh
  180. ## shortcuts to other machines
  181. alias murray='ssh weiyi@murray'
  182. alias nile='ssh weiyi@nile'
  183. alias niles='ssh weiyi@nile-stage'
  184. alias orinoco='ssh weiyi@orinoco'
  185. alias orinocos='ssh weiyi@orinoco-stage'
  186. alias kwai='ssh weiyi@kwai'
  187. alias devbox='ssh root@devbox'
  188. alias dev5='ssh root@dev5'
  189. alias danshui='ssh weiyi@danshui'
  190. alias elrond='ssh weiyi@elrond'
  191. alias samwise='ssh weiyi@samwise'
  192. alias tfine='ssh cinaeco@tfine'
  193. alias blackomelette='ssh cinaeco@10.0.1.1'
  194. ## shortcuts for development
  195. alias migrate='li3 migration db:migrate'
  196. alias oars-log='tail -F /jails/alcatraz/usr/local/www-conf/logs/oars-phplog'
  197. alias schools-log='tail -F /jails/alcatraz/usr/local/www-conf/logs/schools-phplog'
  198. alias delivery-log='tail -F /jails/alcatraz/usr/local/www-conf/logs/delivery-phplog'
  199. alias cdo='cd /jails/alcatraz/usr/local/www/oars'
  200. alias cds='cd /jails/alcatraz/usr/local/www/schools'
  201. alias cdd='cd /jails/alcatraz/usr/local/www/delivery'
  202. alias sqlo='mysql -u oars -p'