1 # http://zsh.sunsite.dk/Guide/
  2 # colors {{{1
  3 autoload colors zsh/terminfo
  4 if [[ "$terminfo[colors]" -ge 8 ]]; then
  5   colors
  6   export COLORTERM=yes
  7 fi
  8 for pr_color in cyan white yellow magenta black blue red grey green default; do
  9   eval local $pr_color='%{$fg[$pr_color]%}'
 10   #  bold color is in capital letters
 11   eval local ${(U)pr_color}='%{$terminfo[bold]$fg[$pr_color]%}'
 12 done
 13 local reset="%{$terminfo[sgr0]%}"
 14 
 15 # directory colors {{{2
 16 if [ -f ${HOME}/.dir_colors ]; then
 17   eval $(dircolors -b ${HOME}/.dir_colors)
 18 elif [ -f /etc/DIR_COLORS ]; then
 19   eval $(dircolors -b /etc/DIR_COLORS)
 20 fi
 21 # }}}
 22 #  prompt {{{1
 23 
 24 local prmt="$RED!"
 25 (( $EUID )) && local prmt=$GREEN
 26 
 27 local conn=''
 28 [[ -n $SSH_TTY ]] && local conn=$YELLOW'ssh '$default
 29 
 30 local screen=''
 31 [[ $TERM = screen* ]] && local screen=$CYAN'scr '$default
 32 
 33 local PS1="$screen$conn$default%20<…<%~ %(?..%(20?.${cyan}susp$default.$RED%?))$prmt>$reset "
 34 local NORMALPROMPT=$PS1
 35 local VIPROMPT="vi$prmt»$reset "
 36 
 37 local PS2="%_$BLUE> $reset"
 38 local RPS1="$BLUE(%(1j.%j job%(2j.s.) $yellow| .)$default%n$RED@$GREEN%m$BLUE)$reset"
 39 
 40 
 41 #  http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
 42 function parse_git_branch
 43 {
 44   ref=$(git symbolic-ref HEAD 2> /dev/null) || return
 45   echo "${MAGENTA}${ref#refs/heads/}$reset "
 46   #  echo "${MAGENTA}git $ref$reset "
 47 }
 48 
 49 function parse_hg_branch
 50 {
 51   ref=$(hg branch 2> /dev/null) || return
 52   echo "${MAGENTA}${ref#refs/heads/}$reset "
 53   #  echo "${MAGENTA}git $ref$reset "
 54 }
 55 
 56 function parse_svn_branch
 57 {
 58   if [[ -d '.svn' ]] then
 59     echo "${MAGENTA}svn$reset "
 60   fi
 61 }
 62 
 63 function setNormalPrompt() {
 64   PS1="$(parse_svn_branch)$(parse_git_branch)$(parse_hg_branch)$NORMALPROMPT"
 65 }
 66 
 67 
 68 # visually indicate vi command mode
 69 # http://www.zsh.org/mla/workers/2006/msg00056.html
 70 zle-keymap-select() {
 71 
 72   if [[ $KEYMAP = vicmd ]]; then
 73     if [[ $PS1 != $VIPROMPT* ]]; then
 74       PS1=$VIPROMPT
 75       zle reset-prompt
 76     fi
 77   else
 78     if [[ $PS1 = $VIPROMPT* ]]; then
 79       setNormalPrompt
 80       zle reset-prompt
 81     fi
 82   fi
 83 }
 84 
 85 zle -N zle-keymap-select
 86 
 87 # environment {{{1
 88 export BROWSER=/usr/bin/firefox
 89 export CC=gcc
 90 export EDITOR='/usr/bin/vim'
 91 # export LANG=en_GB.utf8
 92 # export LANGUAGE="en_GB:en"
 93 # export LC_TIME=de_DE.utf8
 94 # export LC_PAPER=de_DE.utf8
 95 # export LC_MEASUREMENT=de_DE.utf8
 96 # export LC_MONETARY=de_DE.utf8
 97 # export LC_MESSAGES=en_GB.utf8
 98 # export LC_CTYPE=en_GB.utf8
 99 # export LC_COLLATE=en_GB.utf8
100 # export LC_NUMERIC=en_GB.utf8
101 export LANG=de_DE.utf8
102 export LC_MESSAGES=en_GB.utf8
103 export MAIL=$HOME/.maildir;
104 export NNTPSERVER='snews://news.foo.fh-furtwangen.de' # for slrn
105 
106 export MAVEN_OPTS="-Xms256m -Xmx512m"
107 
108 # aliases {{{1
109 alias mv='nocorrect mv'
110 alias cp='nocorrect cp'
111 alias mkdir='nocorrect mkdir -p'
112 alias rd='rmdir'
113 alias ...='cd ../..'
114 alias vp='vimpager'
115 # see the functions for 'mcd'
116 autoload zmv
117 alias zmv='noglob zmv -W'
118 alias py='ipython'
119 alias pt='urxvt -e ipython'
120 
121 alias cal='cal -3m'
122 #  alias dig="echo 'use the djbdns tools\neg. dnsqr NS 0x11.net\n'"
123 #  alias nslookup="echo 'use the djbdns tools': dnsname"
124 
125 # net
126 alias netstat='netstat -A inet -l -e'
127 alias ph="ping heise.de"
128 
129 # inotify tail
130 if [[ -f /usr/bin/inotail || -f /bin/inotail ]] then
131   alias tail='inotail'
132 fi
133 
134 ## ls stuff ##
135 alias ls='ls -F --color=auto'
136 alias ll='ls -alhF --color=auto'
137 alias l='ls -F --color=auto'
138 alias history='history -EfdD'
139 alias h='history'
140 alias gh='h 1 | grep'
141 alias ind='/usr/src/linux/scripts/Lindent'
142 
143 alias genmail='/home/bene/scripts/genmail.pl'
144 alias ranname="nc koeln.ccc.de 23";
145 
146 ## git
147 alias gg='git grep -i'
148 alias log='git log'
149 alias whatchanged='git whatchanged'
150 alias status='git status'
151 alias pull='git pull'
152 alias push='git push'
153 alias commit='git commit'
154 alias branch='git branch'
155 
156 alias grep='grep --color=auto'
157 export PAGER='less -RMi'
158 export MANPAGER=$PAGER
159 alias less=$PAGER
160 #  export LESSCHARSET=utf-8
161 alias diff='colordiff'
162 alias reboot="sudo /sbin/shutdown -r now";
163 alias .off="sudo /sbin/shutdown -h now";
164 alias .str="~/scripts/suspend.sh";
165 
166 # starts VirtualBox after configuring network stuff
167 alias vbox="~/scripts/vbox.sh";
168 
169 alias ifconfig="/sbin/ifconfig";
170 
171 # set this in .screenrc (defutf8 on)
172 # alias screen='screen -U'
173 alias fatlady="ssh fatlady -t screen -RD";
174 alias gaia="ssh gaia";
175 # http://gentoo-wiki.com/TIP_Using_screen
176 #  alias vps="autossh -M $[$RANDOM % 10000+30000] vps -t screen -RDU";
177 alias vps="ssh vps -t screen -RDU";
178 alias epia="ssh epia -t screen -RDU";
179 alias esprit="ssh esprit -t screen -RDU";
180 # seedbox
181 alias sb="ssh sb -t screen -RDU";
182 
183 # completition {{{1
184 zmodload zsh/complist # force to load it, otherwise 'menuselect' keymap isn't available
185 autoload -U zsh/zutils
186 autoload -U compinit
187 compinit
188 zstyle ':completion:*' format 'Completing %d'
189 zstyle ':completion:*' group-name ''
190 zstyle ':completion:*' verbose yes
191 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
192 zstyle ':completion:*:kill:*' menu yes select
193 zstyle ':completion:*:kill:*' force-list always
194 zstyle ':completion:*:processes' command 'ps x -o pid,pcpu,tt,args'
195 zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=$color[white]=$color[red]"
196 zstyle ':completion:*:*:rm:*' file-patterns '*.o:object-files %p:all-files'
197 zstyle ':completion:*:*:wine:*' file-patterns '*.exe:executables *(-/):directories'
198 zstyle ':completion:*:*:(*pdf*|acroread|rm):*' file-sort time
199 zstyle ':completion:*' menu select=2
200 #  scrolling in completition list
201 local LISTPROMPT=
202 
203 ## history settings ##
204 # history {{{1
205 HISTFILE=~/.history
206 HISTSIZE=3000
207 SAVEHIST=3000
208 
209 # options {{{1
210 # man zshoptions
211 setopt INC_APPEND_HISTORY
212 setopt SHARE_HISTORY
213 setopt EXTENDED_HISTORY
214 setopt HIST_IGNORE_DUPS
215 setopt HIST_EXPIRE_DUPS_FIRST
216 #  warn before doing echo foo > bar
217 setopt NO_CLOBBER
218 setopt HIST_ALLOW_CLOBBER
219 setopt HIST_REDUCE_BLANKS
220 
221 setopt NO_BEEP
222 setopt AUTO_CD
223 setopt EXTENDED_GLOB
224 setopt COMPLETE_IN_WORD
225 
226 setopt CORRECT
227 setopt AUTO_PUSHD
228 local DIRSTACKSIZE=20
229 export REPORTTIME=5
230 
231 setopt AUTO_MENU
232 setopt NO_LIST_AMBIGUOUS
233 #  setopt MENU_COMPLETE
234 
235 # bindkey {{{1
236 # man zshzle
237 
238 # next to the incredible powerful vi editing in zle I want some 'standard' readline keybindings
239 # some of them are stolen from zle's emacs keybinding ;)
240 # use CTRL-V <sequence> to insert a shortcut here
241 bindkey -v "^[f"    forward-word
242 bindkey -v "^[F"    forward-word
243 bindkey -v "^[b"    backward-word
244 bindkey -v "^[B"    backward-word
245 bindkey -v "^R"     history-incremental-search-backward
246 bindkey -v "^F"     history-incremental-search-forward
247 bindkey -v "^A"     beginning-of-line
248 bindkey -v "^E"     end-of-line
249 bindkey -v "^[[7~"  beginning-of-line       # home
250 bindkey -v "^[[8~"  end-of-line             # end
251 bindkey -v "^[[1~"  beginning-of-line       # home (in screen)
252 bindkey -v "^[[4~"  end-of-line             # end (in screen)
253 bindkey -v "^ "     vi-cmd-mode
254 bindkey -v "^N"     up-line-or-search
255 bindkey -v "^P"     down-line-or-search
256 bindkey -v "^[d"    kill-word
257 bindkey -v "^[D"    kill-word
258 bindkey -v "^[^?"   backward-kill-word
259 bindkey -v "^H"     backward-kill-word
260 bindkey -v "^k"     kill-line
261 bindkey -v "^K"     kill-line
262 bindkey -r "^["       # don't put me into vi command mode by accident ;)
263 
264 accept-and-execute-line() { zle accept-line ; zle accept-line }
265 zle -N accept-and-execute-line
266 bindkey -M menuselect '^M' accept-and-execute-line
267 bindkey -M menuselect '^U' undo
268 bindkey -M menuselect '^J' accept-and-infer-next-history
269 #  yes, I'm fast
270 local KEYTIMEOUT=5
271 
272 #  functions {{{1
273 
274 # This function sets the window tile to user@host:/workingdir
275 function precmd () {
276   setNormalPrompt
277 
278 case $TERM in
279   rxvt*|screen*|*xterm*|(dt|k)term|Eterm)
280   print -Pn "\e]2;%n@%m:%~\e\134"
281   ;;
282   linux)
283   ;;
284 esac
285 }
286 
287 function leo () { firefox "http://dict.leo.org/?search=$1"; }
288 function dict () { firefox "http://dict.tu-chemnitz.de/?query=$1"; }
289 
290 # mkdir && cd
291 function mcd() { mkdir "$@"; cd "$@" }
292 
293 # create a temporary directory and cd in it
294 function tmp() {
295   randir=/tmp/0-`head -c 20 /dev/urandom | md5sum | head -c 10`;
296   if [[ -d $randir ]]; then
297    # $randir already exists. retry
298     tmp
299   else
300     echo "creating temporary directory $randir"
301     mcd $randir
302   fi
303 }
304 
305 function psg {
306 # using a perlre lookahead 'trick' to prevent grep from
307 # greping it's own process
308 # grep with --enable-pcre needed!
309 ps ax | grep -i -P "$1"'(?!\(\?\!)'
310 }
311 
312 # run some command and notify about the result via the notification-daemon
313 function run () {
314 $@
315 local error=$?
316 if [[ $error -eq 0 ]]; then
317   notify-send "`hostname -s` | terminated:" "$1 $2" -i finish -t 0
318 else
319   notify-send "`hostname -s` | aborted:"    "$1 $2" -u critical -i undo -t 0
320 fi
321 return $error
322 }
323 
324 # show directory stack and ask for a dir to switch to
325 function d () {
326 emulate -L zsh
327 autoload -U colors
328 local color=$fg_bold[cyan]
329 integer i=0
330 dirs -p | while read dir
331   do
332     local num="${$(printf "%-4d " $i)/ /.}"
333     printf " %s  $color%s$reset_color\n" $num $dir
334     (( i++ ))
335   done
336   integer dir=-1
337   read -r 'dir?Jump to directory: ' || return
338   (( dir == -1 )) && return
339   if (( dir < 0 || dir >= i ))
340   then
341     echo d: no such directory stack entry: $dir
342     return 1
343   fi
344   cd ~$dir
345 }
346 
347 #  }}}
348 
349 # man page colors {{{2
350 # http://blog.foosion.org/2008/06/05/colored-manpages/
351 export LESS_TERMCAP_mb=$'\E[01;31m'
352 export LESS_TERMCAP_md=$'\E[01;31m'
353 export LESS_TERMCAP_me=$'\E[0m'
354 export LESS_TERMCAP_se=$'\E[0m'
355 export LESS_TERMCAP_so=$'\E[01;44;33m'
356 export LESS_TERMCAP_ue=$'\E[0m'
357 export LESS_TERMCAP_us=$'\E[01;32m'
358 
359 # host specific settings {{{1
360 test -f ~/.zshrc.host && . ~/.zshrc.host
361 
362 # }}}
363 # vim: set ts=2 sw=2 noet fdm=marker fdl=0 :