# File: ~/.zshrc # Autor: kryptart # Created: Sat-07-Feb 19:54:31 +0100 (CET) 2008 # Last modified: Thu-29-Dec 12:36:30 +0100 (CET) 2011 # --------------------------------------------------------------------- # Note: thanks to grml.org # ********************************************************************* # ********************************************************************* # PROMPT case $TERM in xterm*|xterm-color|rxvt|rxvt-unicode|wterm) PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"' ;; screen) PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"' ;; esac export PATH="$PATH:/usr/sbin" autoload -U promptinit promptinit prompt bart if [[ $TERM = rxvt ]]; then chpwd() {} P='%h | %~' else chpwd () { print -Pn "\e]0;%~\a" } P='%h' fi if [[ $EUID = 0 ]]; then PS1='%{%} '"$P"' %{%} %B' else PS1='%{%} '"$P"' %{%} %B' fi RPROMPT='%b%(0?..%{%} %1v )%2(v.%{%} %{%} %2v .)%{%}' PS2='%{%} %3_ %{%} %B' SPROMPT='%{%}correct %R to %r (ynae)%{%} ' POSTEDIT='' unset P # ********************************************************************* # Module autoload -U zargs autoload -U zmv autoload -U zed autoload -U zcalc autoload -U zftp #autoload -U zle autoload -U files autoload -U stat autoload -U system autoload -U termcap autoload -U terminfo # ********************************************************************* # PARAMETERS fignore=(\~ .o .log .aux .elc .reg .pro .in .md{d,h,hi,hs} .epro .syms) if [[ -f /usr/local/share/zsh/std-funcs.zwc ]]; then fpath=(/usr/local/share/zsh/std-funcs.zwc $fpath ~/.zshfuncs) else fpath=($fpath ~/.zshfuncs) fi path=(~/bin $path) hosts=(localhost) ## history HISTFILE=${HOME}/.zhistory HISTSIZE=200 SAVEHIST=200 ## directory stack DIRSTACKSIZE=30 READNULLCMD=less # ********************************************************************* # vimpager export PAGER=/usr/local/bin/vimpager alias less=$PAGER alias zless=$PAGER # ********************************************************************* # ALIASES # ********************************************************************* # FUNCTIONS ll() { ls -la --color=auto "$@" | more } .() { if [[ $# -eq 0 ]]; then cd $OLDPWD else builtin . $* fi } # ********************************************************************* # OPTIONS setopt autocd autolist automenu autopushd braceccl cdablevars setopt correct extendedglob noflowcontrol setopt histignoredups histignorespace histnostore listtypes longlistjobs setopt cshnullglob magicequalsubst listpacked setopt numericglobsort pushdignoredups pushdminus pushdsilent setopt pushdtohome rcexpandparam rcquotes setopt sunkeyboardhack zle nobadpattern autoremoveslash setopt completeinword autoparamkeys setopt alwayslastprompt unsetopt bgnice norcs notify nonomatch hashdirs listambiguous # ********************************************************************* # COMPLETION zmodload zsh/complist zmodload zsh/computil autoload compinit compinit zstyle ':completion:*:*:cd:*' tag-order local-directories zstyle ':completion:*:*:lp*:*' tag-order jobs zstyle ':completion:*:*:(kill|wait):*' tag-order 'jobs processes' zstyle ':completion:*:*:(kill|wait):*' group-order jobs zstyle ':completion:*:*' users-hosts \ abakus-2@baron-net.eu \ abakus@baron-net.eu zstyle ':completion:*' use-compctl false zstyle ':completion:*:match:*' original yes zstyle ':completion:incremental:*' list yes zstyle ':completion:incremental:*' prompt 'incremental (%c): %u%s%a %l' zstyle ':completion:*:oldlist:*' menu verbose zstyle ':completion:predict:*' completer _complete zstyle ':completion:predict:*' list always zstyle ':completion:predict:*' cursor key zstyle ':completion:predict:*' special-dirs yes zstyle ':completion:*:default' menu select zstyle ':completion:*:(correct|approximate):*' max-errors 2 numeric zstyle ':completion:*:(correct|approximate)-*:*' original yes zstyle ':completion:*:paths' expand prefix zstyle ':completion:*:option(-*|s)' auto-description 'specify %d' zstyle ':completion:*:processes' command ps --forest -u $EUID -o pid,cmd zstyle ':completion:*' verbose yes zstyle ':completion:*' prefix-needed yes zstyle ':completion:*' prefix-hidden no zstyle ':completion:*' last-prompt yes zstyle ':completion:*' users ivo root zstyle ':completion:*:complete:*:(all-|)files' ignored-patterns \ '?*~' '?*.(o|log|aux|elc|reg|pro|md[dh]|mdh[is]|syms|epro)' '(|*/)CVS' zstyle ':completion:*:complete:*:(local|path)-directories' ignored-patterns '(|*/)CVS' zstyle ':completion:*' group-name '' zstyle ':completion:*:jobs' prefix-needed no zstyle ':completion:*' ignore-parents pwd parent zstyle ':completion:*:complete:*:(functions|parameters|association-keys)' ignored-patterns '_*' zstyle ':completion:::::' completer _complete _match _ignored _correct _approximate _prefix zstyle ':completion:*' matcher-list '' 'm:{a-z-}={A-Z_} r:|[-_./]=* r:|=*' 'm:{a-z-}={A-Z_} l:|=* r:|=*' #zstyle ':completion:*' matcher-list '' 'm:{a-zÖÄÜA-Zöäü}={A-Zöäüa-zÖÄÜ} r:|[-_./]=*' 'm:{a-zÖÄÜA-Zöäü}={A-Zöäüa-zÖÄÜ} l:|=* r:|=*' zstyle ':completion:*:*:diff:*:version' command =diff -v zstyle ':completion:*:*:(p|gview|xdvi|kill|psnup):*' menu yes select zstyle ':completion:*:*:(p|gview|xdvi|psnup):*' file-sort time zstyle ':completion:*:default' list-prompt '%{%} Line %l Continue? %b' zstyle ':completion:*:default' select-prompt '%{%} Match %m Line %l %p %b' zstyle ':completion:*:(cp|mv|rm):*' ignore-line yes zstyle ':completion:*:kill:*' force-list always zstyle ':completion:*:*:*make:*:targets' command awk \''/^[a-zA-Z0-9][^\/\t=]+:/ {print $1}'\' \$file zstyle ':completion:*history*' remove-all-dups yes zstyle ':completion:*history*' stop yes zstyle ':completion:*:(correct|approximate)-*:*:corrections' format '%{%}-------------------- %{%} correct %{%} %{%} %e %{%} %{%} %-35.35o %{%}' zstyle ':completion:*:expand:*:expansions' format '%{%}--------------------------- %{%} expand %{%} %{%} %-35.35o %{%}' zstyle ':completion:*:default' list-colors 'tc=35' 'ma=41;37' 'st=43;36' 'di=31;1' 'ex=33;1' \ 'ln=32' '*CVS=35' '*rej=31;1' '*orig=35' zstyle ':completion:*:descriptions' format '%{%}-------------------------------------- %{%} %-35.35d %{%}' zstyle ':completion:*:messages' format '%{%}-------------------------------------- %{%} %-35.35d %{%}' zstyle ':completion:*:warnings' format '%{%}-------------------------------------- %{%} no match for %{%} %{%}%D%{%}' zstyle ':completion:*:processes' list-colors \ '=(#b)( #[0-9]#)[^[/0-9a-zA-Z]#(*)=34=37;1=30;1' zstyle ':completion:*:parameters' list-colors '=_*=33' '=[^a-zA-Z]*=31' zstyle ':completion:*:functions' list-colors '=_*=33' '=*-*=31' zstyle ':completion:*:original' list-colors '=*=31;1' zstyle ':completion:*:all-expansions' list-colors '=*=32' zstyle ':completion:*:reserved-words' list-colors '=*=31' zstyle ':completion:*:(jobs|directory-stack|indexes)' list-colors \ '=(#b)(*) -- (*)=35;1=31;1=33;1' zstyle ':completion:*:(options|values)' list-colors \ '=(#b)(*)-- (*)=35;1=31;1=33;1' '=*=31;1' zstyle ':completion:*::lp*:jobs' list-colors '=(#b)* [0-9] ##([^ ]##) ##([^ ]##) ##([^ ]##) ##(*)=35=32=31;1=33;1=32' SELECTMIN=5 ZLS_COLOURS='ma=7:di=0:ex=0:bd=0:cd=0:ln=0:so=0' bindkey -M menuselect '/' accept-and-infer-next-history \ '^U' undo \ '^@' accept-and-menu-complete \ '^A' .beginning-of-line-hist \ '^E' .end-of-line-hist \ '^P' vi-forward-blank-word \ '^N' vi-backward-blank-word \ '\e<' beginning-of-history \ '\e>' end-of-history # ********************************************************************* # DEFAULT BROWSER (( ${+BROWSER} )) || export BROWSER="links" # ********************************************************************* # GLOBBING / print some useful informations on globbing H-Glob() { echo -e " / directories . plain files @ symbolic links = sockets p named pipes (FIFOs) * executable plain files (0100) % device files (character or block special) %b block special files %c character special files r owner-readable files (0400) w owner-writable files (0200) x owner-executable files (0100) A group-readable files (0040) I group-writable files (0020) E group-executable files (0010) R world-readable files (0004) W world-writable files (0002) X world-executable files (0001) s setuid files (04000) S setgid files (02000) t files with the sticky bit (01000) print *(m-1) # Dateien, die vor bis zu einem Tag modifiziert wurden. print *(a1) # Dateien, auf die vor einem Tag zugegriffen wurde. print *(@) # Nur Links print *(Lk+50) # Dateien die ueber 50 Kilobytes grosz sind print *(Lk-50) # Dateien die kleiner als 50 Kilobytes sind print **/*.c # Alle *.c - Dateien unterhalb von \$PWD print **/*.c~file.c # Alle *.c - Dateien, aber nicht 'file.c' print (foo|bar).* # Alle Dateien mit 'foo' und / oder 'bar' am Anfang print *~*.* # Nur Dateien ohne '.' in Namen chmod 644 *(.^x) # make all non-executable files publically readable print -l *(.c|.h) # Nur Dateien mit dem Suffix '.c' und / oder '.h' print **/*(g:users:) # Alle Dateien/Verzeichnisse der Gruppe >users< echo /proc/*/cwd(:h:t:s/self//) # Analog zu >ps ax | awk '{print $1}'<" } # ********************************************************************* # MONITORING # list files which have been modified within the last x days new() { print -l *(m-$1) } # ********************************************************************* # STATUS / print status status() { print "" print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")"" print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)" print "Term..: $TTY ($TERM), $BAUD bauds, $COLUMNS x $LINES cars" print "Login.: $LOGNAME (UID = $EUID) on $HOST" print "Uptime:$(uptime)" print "" } # ********************************************************************* # CREATE ISO / Create an ISO image. # You are prompted for\\&\quad volume name, filename and directory. mkiso() { echo " * Volume name " read volume echo " * ISO Name (ie. tmp.iso)" read iso echo " * Directory or File" read files mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files } # ********************************************************************* # SIMPLE THUMBNAILS GENERATOR genthumbs() { rm -rf thumb-* index.html echo " Images " > index.html for f in *.(gif|jpeg|jpg|png) ; do convert -size 100x200 "$f" -resize 100x200 thumb-"$f" echo " " >> index.html done echo " " >> index.html } # ********************************************************************* # RENAMING PICTURES # rename pictures based on information found in exif headers exirename() { if [[ $# -lt 1 ]] ; then echo 'Usage: jpgrename $FILES' >& 2 return 1 else echo -n 'Checking for jhead with version newer than 1.9: ' jhead_version=`jhead -h | grep 'used by most Digital Cameras. v.*' | awk '{print $6}' | tr -d v` if [[ $jhead_version > '1.9' ]]; then echo 'success - now running jhead.' jhead -n%Y-%m-%d_%Hh%M_%f $* else echo 'failed - exiting.' fi fi } # ********************************************************************* # SMARTINDENT / indent source code smart-indent() { indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs $* } # ********************************************************************* # OPEN FILE / open file in gvim and jump to line # http://www.downgra.de/archives/2007/05/08/T19_21_11/ j2v() { local -a params params=(${*//(#m):[0-9]*:/\\n+${MATCH//:/}}) # replace ':23:' to '\n+23' params=(${(s|\n|)${(j|\n|)params}}) # join array using '\n', then split on all '\n' gvim ${params} } # ********************************************************************** # PRINT SPECIFIC LINE OF FILE(S) linenr () { if [ $# -lt 2 ] ; then print "Usage: linenr [,] " ; return 1 elif [ $# -eq 2 ] ; then local number=$1 local file=$2 command ed -s $file <<< "${number}n" else local number=$1 shift for file in "$@" ; do if [ ! -d $file ] ; then echo "${file}:" command ed -s $file <<< "${number}n" 2> /dev/null else continue fi done | less fi } # ********************************************************************* # WEATHER / retrieve weather information on the console # Usage example: 'weather KRDM' weather() { [[ -n "$1" ]] || { print 'Usage: weather ' >&2 print 'List of stations: http://en.wikipedia.org/wiki/List_of_airports_by_ICAO_code'>&2 return 1 } local PLACE="${1:u}" local FILE="$HOME/.weather/$PLACE" local LOG="$HOME/.weather/log" [[ -d $HOME/.weather ]] || { print -n "Creating $HOME/.weather: " mkdir $HOME/.weather print 'done' } print "Retrieving information for ${PLACE}:" print wget -T 10 --no-verbose --output-file=$LOG --output-document=$FILE http://weather.noaa.gov/pub/data/observations/metar/decoded/$PLACE.TXT if [[ $? -eq 0 ]] ; then if [[ -n "$VERBOSE" ]] ; then cat $FILE else DATE=$(grep 'UTC' $FILE | sed 's#.* /##') TEMPERATURE=$(awk '/Temperature/ { print $4" degree Celcius / " $2" degree Fahrenheit" }' $FILE| tr -d '(') echo "date: $DATE" echo "temp: $TEMPERATURE" fi else print "There was an error retrieving the weather information for $PLACE" >&2 cat $LOG return 1 fi } # *********************************************************************