zshrc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #allow tab completion in the middle of a word
  22. setopt COMPLETE_IN_WORD
  23. ## Correct my spelling
  24. #setopt CORRECT
  25. ## Don't ask me
  26. setopt RMSTARSILENT
  27. ## Don't require 'cd'
  28. #setopt AUTOCD
  29. ## Automatically pushd - then I can go to an old dir with cd - <tab> (pick no.)
  30. setopt AUTOPUSHD
  31. export DIRSTACKSIZE=11 # stack size of eleven gives me a list with ten entries
  32. ## Autocomplete hosts from .ssh/known_hosts
  33. #local _myhosts
  34. _myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} )
  35. zstyle ':completion:*' hosts $_myhosts
  36. HISTSIZE=10000
  37. SAVEHIST=10000
  38. HISTFILE=~/.zsh_history
  39. #####################
  40. # SHELL ENVIRONMENT #
  41. #####################
  42. ## Ctrl-W stops at a directory
  43. ## see http://www.zsh.org/mla/users/1995/msg00088.html
  44. WORDCHARS='*?_-.[]~\!#$%^(){}<>|`@#$%^*()+:?'
  45. ## set up my prompt
  46. export PS1="%{${fg[yellow]}%}[%n@%m] %{${fg[green]}%}%3~ %# %{${fg[default]}%}"
  47. ## color STDERR red
  48. #exec 2>>(while read line; do
  49. # print '\e[91m'${(q)line}'\e[0m' > /dev/tty; done &)
  50. #if [ "`uname`" = "Darwin" ]; then
  51. # 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
  52. # alias run='open -a'
  53. #fi
  54. ## set list colours
  55. # TODO do we need to rework this?
  56. 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:'
  57. #############
  58. # SSH AGENT #
  59. #############
  60. # Don't do for OSX, as it has it's own handling of ssh-agent
  61. if [ `uname` != Darwin ]; then
  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. fi
  89. #############
  90. # FUNCTIONS #
  91. #############
  92. trash() { mv $@ ~/.Trash }
  93. pc() { awk "{print \$$1}" }
  94. mcd() { mkdir -p "$1" && cd "$1" }
  95. calc() { echo "$@" | bc -l -q -i }
  96. dont() { echo "OK, I won't!" }
  97. settab() { echo -ne "\e]1;$1\a" }
  98. settabh() { settab `hostname | cut -d. -f1` }
  99. ###########
  100. # ALIASES #
  101. ###########
  102. ## history
  103. alias h='history'
  104. ## folder listing/traversal
  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 -g ...="../.."
  116. alias -g ....="../../.."
  117. alias -g .....="../../../.."
  118. ## disk usage
  119. alias df='df -h'
  120. alias du='du -sh'
  121. ## file manipulation
  122. alias mkdir='nocorrect mkdir'
  123. alias mv='nocorrect mv'
  124. alias cp='nocorrect cp'
  125. alias touch='nocorrect touch'
  126. alias ln='nocorrect ln'
  127. ## grep (which is mostly replaced with ack anyway)
  128. alias -g G="| grep"
  129. alias -g g="| grep -i"
  130. alias -g L="| less"
  131. alias -g H="| head"
  132. alias igrep='grep -i'
  133. alias rgrep='grep -R'
  134. alias rigrep='grep -iR'
  135. ## proxy setup
  136. 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;'
  137. 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;'
  138. alias hosts='vim /etc/hosts'
  139. alias graceful='apachectl graceful'
  140. alias flushdns='lookupd -flushcache'
  141. alias bc='bc -l'
  142. alias o.='open .'
  143. alias upd='cvs -q upd -dP'
  144. alias upd-head='cvs -q upd -dPA'
  145. ## git
  146. alias gs='git status'
  147. alias gd='git diff'
  148. alias gds='git diff --staged'
  149. alias ga='git add .'
  150. # update locate data for mac
  151. if [ `uname` = Darwin ]; then
  152. alias updatedb='sudo /usr/libexec/locate.updatedb'
  153. fi
  154. ## common typos
  155. alias vf='cd'
  156. alias xs='cd'
  157. alias ks='ls'
  158. alias ecgi='echo'
  159. ## ensure X11 is running when I gvim, xterm etc
  160. ## TODO do we really need this?
  161. alias xterm='open -a X11 && /usr/X11R6/bin/xterm -sb -sl 5000 -rightbar -fg white -bg black -geometry 100x50+40+20'
  162. alias gvim='open -a X11 && vim -g'
  163. settabh
  164. ## include settings specific to this machine
  165. if [[ -r ~/.zshlocal ]]; then
  166. source ~/.zshlocal
  167. fi