zshrc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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=10000
  39. SAVEHIST=10000
  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. ## color STDERR red
  50. #exec 2>>(while read line; do
  51. # print '\e[91m'${(q)line}'\e[0m' > /dev/tty; done &)
  52. #if [ "`uname`" = "Darwin" ]; then
  53. # 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
  54. # alias run='open -a'
  55. #fi
  56. ## set list colours
  57. # TODO do we need to rework this?
  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. # ALIASES #
  103. ###########
  104. ## history
  105. alias h='history'
  106. ## folder listing/traversal
  107. alias l='ls'
  108. alias l1='ls -1'
  109. alias ll='ls -hl'
  110. alias la='ls -A'
  111. alias lal="ls -Ahl"
  112. alias l.='ls -d .[^.]*'
  113. alias lsd='ls -ld *(-/DN)'
  114. alias lg='ls -l | grep -i'
  115. alias cd..='cd ..';
  116. alias ..='cd ..'
  117. alias -g ...="../.."
  118. alias -g ....="../../.."
  119. alias -g .....="../../../.."
  120. ## disk usage
  121. alias df='df -h'
  122. alias du='du -sh'
  123. ## file manipulation
  124. alias mkdir='nocorrect mkdir'
  125. alias mv='nocorrect mv'
  126. alias cp='nocorrect cp'
  127. alias touch='nocorrect touch'
  128. alias ln='nocorrect ln'
  129. ## grep (which is mostly replaced with ack anyway)
  130. alias -g G="| grep"
  131. alias -g g="| grep -i"
  132. alias -g L="| less"
  133. alias -g H="| head"
  134. alias igrep='grep -i'
  135. alias rgrep='grep -R'
  136. alias rigrep='grep -iR'
  137. ## proxy setup
  138. 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;'
  139. 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;'
  140. alias hosts='vim /etc/hosts'
  141. alias graceful='apachectl graceful'
  142. alias flushdns='lookupd -flushcache'
  143. alias bc='bc -l'
  144. alias o.='open .'
  145. alias upd='cvs -q upd -dP'
  146. alias upd-head='cvs -q upd -dPA'
  147. ## git
  148. alias gs='git status'
  149. alias gd='git diff'
  150. alias gds='git diff --staged'
  151. alias ga='git add .'
  152. # update locate data for mac
  153. if [ `uname` = Darwin ]; then
  154. alias updatedb='sudo /usr/libexec/locate.updatedb'
  155. fi
  156. ## common typos
  157. alias vf='cd'
  158. alias xs='cd'
  159. alias ks='ls'
  160. alias ecgi='echo'
  161. ## ensure X11 is running when I gvim, xterm etc
  162. ## TODO do we really need this?
  163. alias xterm='open -a X11 && /usr/X11R6/bin/xterm -sb -sl 5000 -rightbar -fg white -bg black -geometry 100x50+40+20'
  164. alias gvim='open -a X11 && vim -g'
  165. settabh
  166. ## include settings specific to this machine
  167. if [[ -r ~/.zshlocal ]]; then
  168. source ~/.zshlocal
  169. fi