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 # http://amarok.kde.org/wiki/2.0_Development_HowTo#Install_ccache_to_speed_up_compilation_.28optional.2C_recommended.29
109 export PATH=/usr/lib/ccache/bin:$PATH
110 export CCACHE_DIR='/var/tmp/ccache-bene'
111 
112 # aliases {{{1
113 alias vi='vim'
114 alias mv='nocorrect mv'
115 alias cp='nocorrect cp'
116 alias mkdir='nocorrect mkdir -p'
117 alias rd='rmdir'
118 alias ...='cd ../..'
119 alias vp='vimpager'
120 # see the functions for 'mcd'
121 autoload zmv
122 alias zmv='noglob zmv -W'
123 alias py='ipython'
124 alias pt='urxvt -e ipython'
125 
126 alias cal='cal -3m'
127 #  alias dig="echo 'use the djbdns tools\neg. dnsqr NS 0x11.net\n'"
128 #  alias nslookup="echo 'use the djbdns tools': dnsname"
129 
130 # net
131 alias netstat='netstat -A inet -l -e'
132 alias ph="ping heise.de"
133 
134 # inotify tail
135 if [[ -f /usr/bin/inotail || -f /bin/inotail ]] then
136   alias tail='inotail'
137 fi
138 
139 ## ls stuff ##
140 alias ls='ls -F --color=auto'
141 alias ll='ls -alhF --color=auto'
142 alias l='ls -F --color=auto'
143 alias history='history -EfdD'
144 alias h='history'
145 alias gh='h 1 | grep'
146 alias ind='/usr/src/linux/scripts/Lindent'
147 
148 alias genmail='/home/bene/scripts/genmail.pl'
149 alias ranname="nc koeln.ccc.de 23";
150 
151 ## git
152 alias gg='git grep -i'
153 alias log='git log --graph'
154 alias whatchanged='git whatchanged'
155 alias status='git status'
156 alias pull='git pull'
157 alias push='git push'
158 alias commit='git commit'
159 alias branch='git branch'
160 
161 alias grep='grep --color=auto'
162 export PAGER='less -RMi'
163 export MANPAGER=$PAGER
164 alias less=$PAGER
165 #  export LESSCHARSET=utf-8
166 alias diff='colordiff'
167 alias reboot="sudo /sbin/shutdown -r now";
168 alias .off="sudo /sbin/shutdown -h now";
169 alias .str="~/scripts/suspend.sh";
170 
171 # starts VirtualBox after configuring network stuff
172 alias vbox="~/scripts/vbox.sh";
173 
174 alias ifconfig="/sbin/ifconfig";
175 
176 # set this in .screenrc (defutf8 on)
177 # alias screen='screen -U'
178 alias fatlady="ssh fatlady -t screen -RD";
179 alias gaia="ssh gaia";
180 # http://gentoo-wiki.com/TIP_Using_screen
181 #  alias vps="autossh -M $[$RANDOM % 10000+30000] vps -t screen -RDU";
182 alias vps="ssh vps -t tmux -u attach-session";
183 alias epia="ssh epia -t screen -RDU";
184 alias esprit="ssh esprit -t screen -RDU";
185 # seedbox
186 alias sb62="TERM=rxvt-unicode ssh sb62 -t screen -RDU";
187 alias sb83="TERM=rxvt-unicode ssh sb83";
188 
189 # completition {{{1
190 zmodload zsh/complist # force to load it, otherwise 'menuselect' keymap isn't available
191 autoload -U zsh/zutils
192 autoload -U compinit
193 compinit
194 zstyle ':completion:*' format 'Completing %d'
195 zstyle ':completion:*' group-name ''
196 zstyle ':completion:*' verbose yes
197 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
198 zstyle ':completion:*:kill:*' menu yes select
199 zstyle ':completion:*:kill:*' force-list always
200 zstyle ':completion:*:processes' command 'ps x -o pid,pcpu,tt,args'
201 zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=$color[white]=$color[red]"
202 zstyle ':completion:*:*:rm:*' file-patterns '*.o:object-files %p:all-files'
203 zstyle ':completion:*:*:wine:*' file-patterns '*.exe:executables *(-/):directories'
204 zstyle ':completion:*:*:(*pdf*|acroread|rm):*' file-sort time
205 zstyle ':completion:*' menu select=2
206 #  scrolling in completition list
207 local LISTPROMPT=
208 
209 ## history settings ##
210 # history {{{1
211 HISTFILE=~/.history
212 HISTSIZE=3000
213 SAVEHIST=3000
214 
215 # options {{{1
216 # man zshoptions
217 setopt INC_APPEND_HISTORY
218 setopt SHARE_HISTORY
219 setopt EXTENDED_HISTORY
220 setopt HIST_IGNORE_DUPS
221 setopt HIST_EXPIRE_DUPS_FIRST
222 #  warn before doing echo foo > bar
223 setopt NO_CLOBBER
224 setopt HIST_ALLOW_CLOBBER
225 setopt HIST_REDUCE_BLANKS
226 
227 setopt NO_BEEP
228 setopt AUTO_CD
229 setopt EXTENDED_GLOB
230 setopt COMPLETE_IN_WORD
231 
232 setopt CORRECT
233 setopt AUTO_PUSHD
234 local DIRSTACKSIZE=20
235 export REPORTTIME=5
236 
237 setopt AUTO_MENU
238 setopt NO_LIST_AMBIGUOUS
239 #  setopt MENU_COMPLETE
240 
241 # bindkey {{{1
242 # man zshzle
243 
244 # next to the incredible powerful vi editing in zle I want some 'standard' readline keybindings
245 # some of them are stolen from zle's emacs keybinding ;)
246 # use CTRL-V <sequence> to insert a shortcut here
247 bindkey -v "^[f"    forward-word
248 bindkey -v "^[F"    forward-word
249 bindkey -v "^[b"    backward-word
250 bindkey -v "^[B"    backward-word
251 bindkey -v "^R"     history-incremental-search-backward
252 bindkey -v "^F"     history-incremental-search-forward
253 bindkey -v "^A"     beginning-of-line
254 bindkey -v "^E"     end-of-line
255 bindkey -v "^[[7~"  beginning-of-line       # home
256 bindkey -v "^[[8~"  end-of-line             # end
257 bindkey -v "^[[1~"  beginning-of-line       # home (in screen)
258 bindkey -v "^[[4~"  end-of-line             # end (in screen)
259 bindkey -v "^ "     vi-cmd-mode
260 bindkey -v "^N"     up-line-or-search
261 bindkey -v "^P"     down-line-or-search
262 bindkey -v "^[d"    kill-word
263 bindkey -v "^[D"    kill-word
264 bindkey -v "^[^?"   backward-kill-word
265 bindkey -v "^H"     backward-kill-word
266 bindkey -v "^k"     kill-line
267 bindkey -v "^K"     kill-line
268 bindkey -r "^["       # don't put me into vi command mode by accident ;)
269 
270 accept-and-execute-line() { zle accept-line ; zle accept-line }
271 zle -N accept-and-execute-line
272 bindkey -M menuselect '^M' accept-and-execute-line
273 bindkey -M menuselect '^U' undo
274 bindkey -M menuselect '^J' accept-and-infer-next-history
275 #  yes, I'm fast
276 local KEYTIMEOUT=5
277 
278 #  functions {{{1
279 
280 # This function sets the window tile to user@host:/workingdir
281 function precmd () {
282   setNormalPrompt
283 
284 case $TERM in
285   rxvt*|screen*|*xterm*|(dt|k)term|Eterm)
286   print -Pn "\e]2;%n@%m:%~\e\134"
287   ;;
288   linux)
289   ;;
290 esac
291 }
292 
293 function leo () { firefox "http://dict.leo.org/?search=$1"; }
294 function dict () { firefox "http://dict.tu-chemnitz.de/?query=$1"; }
295 # https://dgl.cx/wikipedia-dns
296 # variant 1: (has troubles with unicode)
297 #  function wp () { host -t txt "$@.wp.dg.cx" }
298 function wp () { dig +short txt "$1.wp.dg.cx" | perl -pe's/\\(\d{1,3})/chr $1/eg' }
299 
300 # mkdir && cd
301 function mcd() { mkdir "$@"; cd "$@" }
302 
303 # create a temporary directory and cd in it
304 function tmp {
305   nr=$1
306   if [[ "$nr" -eq "" ]]; then
307     nr=1
308   fi
309 
310   nr=`printf "%03d" $nr`
311   randir=/tmp/$nr
312   while [[ -d $randir ]]; do
313     nr=`printf "%03d" $(($nr+1))`
314     randir=/tmp/$nr
315   done
316   echo "creating temporary directory $randir"
317   mcd $randir
318 }
319 
320 function psg {
321 # using a perlre lookahead 'trick' to prevent grep from
322 # greping it's own process
323 # grep with --enable-pcre needed!
324 ps ax | grep -i -P "$1"'(?!\(\?\!)'
325 }
326 
327 # run some command and notify about the result via the notification-daemon
328 function run () {
329 $@
330 local error=$?
331 if [[ $error -eq 0 ]]; then
332   notify-send "`hostname -s` | terminated:" "$1 $2" -i finish -t 0
333 else
334   notify-send "`hostname -s` | aborted:"    "$1 $2" -u critical -i undo -t 0
335 fi
336 return $error
337 }
338 
339 # show directory stack and ask for a dir to switch to
340 function d () {
341 emulate -L zsh
342 autoload -U colors
343 local color=$fg_bold[cyan]
344 integer i=0
345 dirs -p | while read dir
346   do
347     local num="${$(printf "%-4d " $i)/ /.}"
348     printf " %s  $color%s$reset_color\n" $num $dir
349     (( i++ ))
350   done
351   integer dir=-1
352   read -r 'dir?Jump to directory: ' || return
353   (( dir == -1 )) && return
354   if (( dir < 0 || dir >= i ))
355   then
356     echo d: no such directory stack entry: $dir
357     return 1
358   fi
359   cd ~$dir
360 }
361 
362 # show and highlighy dirty and writeback pages
363 function dirty () {
364   while [ 1 ];
365   do
366     cat /proc/meminfo | perl -pe 's/(Writeback.*|Dirty.*)/\033[46;1m$1\033[0m/ig;'
367     sleep 1
368   done
369 }
370 
371 #  }}}
372 
373 # http://linuxsysadminblog.com/2009/06/howto-get-started-with-amazon-ec2-api-tools/
374 export EC2_PRIVATE_KEY=~/.ec2/pk.pem
375 export EC2_CERT=~/.ec2/cert.pem
376 
377 # man page colors {{{2
378 # http://blog.foosion.org/2008/06/05/colored-manpages/
379 export LESS_TERMCAP_mb=$'\E[01;31m'
380 export LESS_TERMCAP_md=$'\E[01;31m'
381 export LESS_TERMCAP_me=$'\E[0m'
382 export LESS_TERMCAP_se=$'\E[0m'
383 export LESS_TERMCAP_so=$'\E[01;44;33m'
384 export LESS_TERMCAP_ue=$'\E[0m'
385 export LESS_TERMCAP_us=$'\E[01;32m'
386 
387 # host specific settings {{{1
388 test -f ~/.zshrc.host && . ~/.zshrc.host
389 
390 # }}}
391 # vim: set ts=2 sw=2 noet fdm=marker fdl=0 :