# http://zsh.sunsite.dk/Guide/ # colors {{{1 autoload colors zsh/terminfo if [[ "$terminfo[colors]" -ge 8 ]]; then colors export COLORTERM=yes fi for pr_color in cyan white yellow magenta black blue red grey green default; do eval local $pr_color='%{$fg[$pr_color]%}' # bold color is in capital letters eval local ${(U)pr_color}='%{$terminfo[bold]$fg[$pr_color]%}' done local reset="%{$terminfo[sgr0]%}" # directory colors {{{2 if [ -f ${HOME}/.dir_colors ]; then eval $(dircolors -b ${HOME}/.dir_colors) elif [ -f /etc/DIR_COLORS ]; then eval $(dircolors -b /etc/DIR_COLORS) fi # }}} # prompt {{{1 local prmt="$RED!" (( $EUID )) && local prmt=$GREEN local conn='' [[ -n $SSH_TTY ]] && local conn=$YELLOW'ssh '$default local screen='' [[ $TERM = screen* ]] && local screen=$CYAN'scr '$default local PS1="$screen$conn$default%20<…<%~ %(?..%(20?.${cyan}susp$default.$RED%?))$prmt>$reset " local NORMALPROMPT=$PS1 local VIPROMPT="vi$prmt»$reset " local PS2="%_$BLUE> $reset" local RPS1="$BLUE(%(1j.%j job%(2j.s.) $yellow| .)$default%n$RED@$GREEN%m$BLUE)$reset" # http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/ function parse_git_branch { ref=$(git symbolic-ref HEAD 2> /dev/null) || return echo "${MAGENTA}${ref#refs/heads/}$reset " # echo "${MAGENTA}git $ref$reset " } function parse_hg_branch { ref=$(hg branch 2> /dev/null) || return echo "${MAGENTA}${ref#refs/heads/}$reset " # echo "${MAGENTA}git $ref$reset " } function parse_svn_branch { if [[ -d '.svn' ]] then echo "${MAGENTA}svn$reset " fi } function setNormalPrompt() { PS1="$(parse_svn_branch)$(parse_git_branch)$(parse_hg_branch)$NORMALPROMPT" } # visually indicate vi command mode # http://www.zsh.org/mla/workers/2006/msg00056.html zle-keymap-select() { if [[ $KEYMAP = vicmd ]]; then if [[ $PS1 != $VIPROMPT* ]]; then PS1=$VIPROMPT zle reset-prompt fi else if [[ $PS1 = $VIPROMPT* ]]; then setNormalPrompt zle reset-prompt fi fi } zle -N zle-keymap-select # environment {{{1 export BROWSER=/usr/bin/firefox export CC=gcc export EDITOR='/usr/bin/vim' # export LANG=en_GB.utf8 # export LANGUAGE="en_GB:en" # export LC_TIME=de_DE.utf8 # export LC_PAPER=de_DE.utf8 # export LC_MEASUREMENT=de_DE.utf8 # export LC_MONETARY=de_DE.utf8 # export LC_MESSAGES=en_GB.utf8 # export LC_CTYPE=en_GB.utf8 # export LC_COLLATE=en_GB.utf8 # export LC_NUMERIC=en_GB.utf8 export LANG=de_DE.utf8 export LC_MESSAGES=en_GB.utf8 export MAIL=$HOME/.maildir; export NNTPSERVER='snews://news.foo.fh-furtwangen.de' # for slrn export MAVEN_OPTS="-Xms256m -Xmx512m" # aliases {{{1 alias mv='nocorrect mv' alias cp='nocorrect cp' alias mkdir='nocorrect mkdir -p' alias rd='rmdir' alias ...='cd ../..' alias vp='vimpager' # see the functions for 'mcd' autoload zmv alias zmv='noglob zmv -W' alias py='ipython' alias pt='urxvt -e ipython' alias cal='cal -3m' # alias dig="echo 'use the djbdns tools\neg. dnsqr NS 0x11.net\n'" # alias nslookup="echo 'use the djbdns tools': dnsname" # net alias netstat='netstat -A inet -l -e' alias ph="ping heise.de" # inotify tail if [[ -f /usr/bin/inotail || -f /bin/inotail ]] then alias tail='inotail' fi ## ls stuff ## alias ls='ls -F --color=auto' alias ll='ls -alhF --color=auto' alias l='ls -F --color=auto' alias history='history -EfdD' alias h='history' alias gh='h 1 | grep' alias ind='/usr/src/linux/scripts/Lindent' alias genmail='/home/bene/scripts/genmail.pl' alias ranname="nc koeln.ccc.de 23"; ## git alias gg='git grep -i' alias log='git log' alias whatchanged='git whatchanged' alias status='git status' alias pull='git pull' alias push='git push' alias commit='git commit' alias branch='git branch' alias grep='grep --color=auto' export PAGER='less -RMi' export MANPAGER=$PAGER alias less=$PAGER # export LESSCHARSET=utf-8 alias diff='colordiff' alias reboot="sudo /sbin/shutdown -r now"; alias .off="sudo /sbin/shutdown -h now"; alias .str="~/scripts/suspend.sh"; # starts VirtualBox after configuring network stuff alias vbox="~/scripts/vbox.sh"; alias ifconfig="/sbin/ifconfig"; # set this in .screenrc (defutf8 on) # alias screen='screen -U' alias fatlady="ssh fatlady -t screen -RD"; alias gaia="ssh gaia"; # http://gentoo-wiki.com/TIP_Using_screen # alias vps="autossh -M $[$RANDOM % 10000+30000] vps -t screen -RDU"; alias vps="ssh vps -t screen -RDU"; alias epia="ssh epia -t screen -RDU"; alias esprit="ssh esprit -t screen -RDU"; # seedbox alias sb="ssh sb -t screen -RDU"; # completition {{{1 zmodload zsh/complist # force to load it, otherwise 'menuselect' keymap isn't available autoload -U zsh/zutils autoload -U compinit compinit zstyle ':completion:*' format 'Completing %d' zstyle ':completion:*' group-name '' zstyle ':completion:*' verbose yes zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} zstyle ':completion:*:kill:*' menu yes select zstyle ':completion:*:kill:*' force-list always zstyle ':completion:*:processes' command 'ps x -o pid,pcpu,tt,args' zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=$color[white]=$color[red]" zstyle ':completion:*:*:rm:*' file-patterns '*.o:object-files %p:all-files' zstyle ':completion:*:*:wine:*' file-patterns '*.exe:executables *(-/):directories' zstyle ':completion:*:*:(*pdf*|acroread|rm):*' file-sort time zstyle ':completion:*' menu select=2 # scrolling in completition list local LISTPROMPT= ## history settings ## # history {{{1 HISTFILE=~/.history HISTSIZE=3000 SAVEHIST=3000 # options {{{1 # man zshoptions setopt INC_APPEND_HISTORY setopt SHARE_HISTORY setopt EXTENDED_HISTORY setopt HIST_IGNORE_DUPS setopt HIST_EXPIRE_DUPS_FIRST # warn before doing echo foo > bar setopt NO_CLOBBER setopt HIST_ALLOW_CLOBBER setopt HIST_REDUCE_BLANKS setopt NO_BEEP setopt AUTO_CD setopt EXTENDED_GLOB setopt COMPLETE_IN_WORD setopt CORRECT setopt AUTO_PUSHD local DIRSTACKSIZE=20 export REPORTTIME=5 setopt AUTO_MENU setopt NO_LIST_AMBIGUOUS # setopt MENU_COMPLETE # bindkey {{{1 # man zshzle # next to the incredible powerful vi editing in zle I want some 'standard' readline keybindings # some of them are stolen from zle's emacs keybinding ;) # use CTRL-V to insert a shortcut here bindkey -v "^[f" forward-word bindkey -v "^[F" forward-word bindkey -v "^[b" backward-word bindkey -v "^[B" backward-word bindkey -v "^R" history-incremental-search-backward bindkey -v "^F" history-incremental-search-forward bindkey -v "^A" beginning-of-line bindkey -v "^E" end-of-line bindkey -v "[7~" beginning-of-line # home bindkey -v "[8~" end-of-line # end bindkey -v "[1~" beginning-of-line # home (in screen) bindkey -v "[4~" end-of-line # end (in screen) bindkey -v "^ " vi-cmd-mode bindkey -v "^N" up-line-or-search bindkey -v "^P" down-line-or-search bindkey -v "^[d" kill-word bindkey -v "^[D" kill-word bindkey -v "^[^?" backward-kill-word bindkey -v "^H" backward-kill-word bindkey -v "^k" kill-line bindkey -v "^K" kill-line bindkey -r "^[" # don't put me into vi command mode by accident ;) accept-and-execute-line() { zle accept-line ; zle accept-line } zle -N accept-and-execute-line bindkey -M menuselect '^M' accept-and-execute-line bindkey -M menuselect '^U' undo bindkey -M menuselect '^J' accept-and-infer-next-history # yes, I'm fast local KEYTIMEOUT=5 # functions {{{1 # This function sets the window tile to user@host:/workingdir function precmd () { setNormalPrompt case $TERM in rxvt*|screen*|*xterm*|(dt|k)term|Eterm) print -Pn "\e]2;%n@%m:%~\e\134" ;; linux) ;; esac } function leo () { firefox "http://dict.leo.org/?search=$1"; } function dict () { firefox "http://dict.tu-chemnitz.de/?query=$1"; } # mkdir && cd function mcd() { mkdir "$@"; cd "$@" } # create a temporary directory and cd in it function tmp() { randir=/tmp/0-`head -c 20 /dev/urandom | md5sum | head -c 10`; if [[ -d $randir ]]; then # $randir already exists. retry tmp else echo "creating temporary directory $randir" mcd $randir fi } function psg { # using a perlre lookahead 'trick' to prevent grep from # greping it's own process # grep with --enable-pcre needed! ps ax | grep -i -P "$1"'(?!\(\?\!)' } # run some command and notify about the result via the notification-daemon function run () { $@ local error=$? if [[ $error -eq 0 ]]; then notify-send "`hostname -s` | terminated:" "$1 $2" -i finish -t 0 else notify-send "`hostname -s` | aborted:" "$1 $2" -u critical -i undo -t 0 fi return $error } # show directory stack and ask for a dir to switch to function d () { emulate -L zsh autoload -U colors local color=$fg_bold[cyan] integer i=0 dirs -p | while read dir do local num="${$(printf "%-4d " $i)/ /.}" printf " %s $color%s$reset_color\n" $num $dir (( i++ )) done integer dir=-1 read -r 'dir?Jump to directory: ' || return (( dir == -1 )) && return if (( dir < 0 || dir >= i )) then echo d: no such directory stack entry: $dir return 1 fi cd ~$dir } # }}} # man page colors {{{2 # http://blog.foosion.org/2008/06/05/colored-manpages/ export LESS_TERMCAP_mb=$'\E[01;31m' export LESS_TERMCAP_md=$'\E[01;31m' export LESS_TERMCAP_me=$'\E[0m' export LESS_TERMCAP_se=$'\E[0m' export LESS_TERMCAP_so=$'\E[01;44;33m' export LESS_TERMCAP_ue=$'\E[0m' export LESS_TERMCAP_us=$'\E[01;32m' # host specific settings {{{1 test -f ~/.zshrc.host && . ~/.zshrc.host # }}} # vim: set ts=2 sw=2 noet fdm=marker fdl=0 :