+if [[ -r ~/.important_commands ]] ; then
+ fc -R ~/.important_commands
+fi
+
+# load the lookup subsystem if it's available on the system
+zrcautoload lookupinit && lookupinit
+
+# variables
+
+# set terminal property (used e.g. by msgid-chooser)
+export COLORTERM="yes"
+
+# aliases
+
+# general
+#a2# Execute \kbd{du -sch}
+alias da='du -sch'
+#a2# Execute \kbd{jobs -l}
+alias j='jobs -l'
+
+# listing stuff
+#a2# Execute \kbd{ls -lSrah}
+alias dir="ls -lSrah"
+#a2# Only show dot-directories
+alias lad='ls -d .*(/)'
+#a2# Only show dot-files
+alias lsa='ls -a .*(.)'
+#a2# Only files with setgid/setuid/sticky flag
+alias lss='ls -l *(s,S,t)'
+#a2# Only show symlinks
+alias lsl='ls -l *(@)'
+#a2# Display only executables
+alias lsx='ls -l *(*)'
+#a2# Display world-{readable,writable,executable} files
+alias lsw='ls -ld *(R,W,X.^ND/)'
+#a2# Display the ten biggest files
+alias lsbig="ls -flh *(.OL[1,10])"
+#a2# Only show directories
+alias lsd='ls -d *(/)'
+#a2# Only show empty directories
+alias lse='ls -d *(/^F)'
+#a2# Display the ten newest files
+alias lsnew="ls -rtlh *(D.om[1,10])"
+#a2# Display the ten oldest files
+alias lsold="ls -rtlh *(D.Om[1,10])"
+#a2# Display the ten smallest files
+alias lssmall="ls -Srl *(.oL[1,10])"
+#a2# Display the ten newest directories and ten newest .directories
+alias lsnewdir="ls -rthdl *(/om[1,10]) .*(D/om[1,10])"
+#a2# Display the ten oldest directories and ten oldest .directories
+alias lsolddir="ls -rthdl *(/Om[1,10]) .*(D/Om[1,10])"
+
+# some useful aliases
+#a2# Remove current empty directory. Execute \kbd{cd ..; rmdir $OLDCWD}
+alias rmcdir='cd ..; rmdir $OLDPWD || cd $OLDPWD'
+
+#a2# ssh with StrictHostKeyChecking=no \\&\quad and UserKnownHostsFile unset
+alias insecssh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
+alias insecscp='scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
+
+# work around non utf8 capable software in utf environment via $LANG and luit
+if check_com isutfenv && check_com luit ; then
+ if check_com -c mrxvt ; then
+ isutfenv && [[ -n "$LANG" ]] && \
+ alias mrxvt="LANG=${LANG/(#b)(*)[.@]*/$match[1].iso885915} luit mrxvt"
+ fi
+
+ if check_com -c aterm ; then
+ isutfenv && [[ -n "$LANG" ]] && \
+ alias aterm="LANG=${LANG/(#b)(*)[.@]*/$match[1].iso885915} luit aterm"
+ fi
+
+ if check_com -c centericq ; then
+ isutfenv && [[ -n "$LANG" ]] && \
+ alias centericq="LANG=${LANG/(#b)(*)[.@]*/$match[1].iso885915} luit centericq"
+ fi
+fi
+
+# useful functions
+
+#f5# Backup \kbd{file {\rm to} file\_timestamp}
+bk() {
+ emulate -L zsh
+ cp -b $1 $1_`date --iso-8601=m`
+}
+
+#f5# cd to directoy and list files
+cl() {
+ emulate -L zsh
+ cd $1 && ls -a
+}
+
+# smart cd function, allows switching to /etc when running 'cd /etc/fstab'
+cd() {
+ if (( ${#argv} == 1 )) && [[ -f ${1} ]]; then
+ [[ ! -e ${1:h} ]] && return 1
+ print "Correcting ${1} to ${1:h}"
+ builtin cd ${1:h}
+ else
+ builtin cd "$@"
+ fi
+}
+
+#f5# Create Directoy and \kbd{cd} to it
+mkcd() {
+ if (( ARGC != 1 )); then
+ printf 'usage: mkcd <new-directory>\n'
+ return 1;
+ fi
+ if [[ ! -d "$1" ]]; then
+ command mkdir -p "$1"
+ else
+ printf '`%s'\'' already exists: cd-ing.\n' "$1"
+ fi
+ builtin cd "$1"
+}
+
+#f5# Create temporary directory and \kbd{cd} to it
+cdt() {
+ local t
+ t=$(mktemp -d)
+ echo "$t"
+ builtin cd "$t"
+}
+
+#f5# Create directory under cursor or the selected area
+# Press ctrl-xM to create the directory under the cursor or the selected area.
+# To select an area press ctrl-@ or ctrl-space and use the cursor.
+# Use case: you type "mv abc ~/testa/testb/testc/" and remember that the
+# directory does not exist yet -> press ctrl-XM and problem solved
+inplaceMkDirs() {
+ local PATHTOMKDIR
+ if ((REGION_ACTIVE==1)); then
+ local F=$MARK T=$CURSOR
+ if [[ $F -gt $T ]]; then
+ F=${CURSOR}
+ T=${MARK}
+ fi
+ # get marked area from buffer and eliminate whitespace
+ PATHTOMKDIR=${BUFFER[F+1,T]%%[[:space:]]##}
+ PATHTOMKDIR=${PATHTOMKDIR##[[:space:]]##}
+ else
+ local bufwords iword
+ bufwords=(${(z)LBUFFER})
+ iword=${#bufwords}
+ bufwords=(${(z)BUFFER})
+ PATHTOMKDIR="${(Q)bufwords[iword]}"
+ fi
+ [[ -z "${PATHTOMKDIR}" ]] && return 1
+ PATHTOMKDIR=${~PATHTOMKDIR}
+ if [[ -e "${PATHTOMKDIR}" ]]; then
+ zle -M " path already exists, doing nothing"
+ else
+ zle -M "$(mkdir -p -v "${PATHTOMKDIR}")"
+ zle end-of-line
+ fi
+}
+#k# mkdir -p <dir> from string under cursor or marked area
+zle -N inplaceMkDirs && bindkey '^xM' inplaceMkDirs
+
+#f5# List files which have been accessed within the last {\it n} days, {\it n} defaults to 1
+accessed() {
+ emulate -L zsh
+ print -l -- *(a-${1:-1})
+}
+
+#f5# List files which have been changed within the last {\it n} days, {\it n} defaults to 1
+changed() {
+ emulate -L zsh
+ print -l -- *(c-${1:-1})
+}
+
+#f5# List files which have been modified within the last {\it n} days, {\it n} defaults to 1
+modified() {
+ emulate -L zsh
+ print -l -- *(m-${1:-1})
+}
+# modified() was named new() in earlier versions, add an alias for backwards compatibility
+check_com new || alias new=modified
+
+# use colors when GNU grep with color-support
+#a2# Execute \kbd{grep -{}-color=auto}
+(( $#grep_options > 0 )) && alias grep='grep '${grep_options:+"${grep_options[*]}"}
+
+# Translate DE<=>EN
+# 'translate' looks up fot a word in a file with language-to-language
+# translations (field separator should be " : "). A typical wordlist looks
+# like at follows:
+# | english-word : german-transmission
+# It's also only possible to translate english to german but not reciprocal.
+# Use the following oneliner to turn back the sort order:
+# $ awk -F ':' '{ print $2" : "$1" "$3 }' \
+# /usr/local/lib/words/en-de.ISO-8859-1.vok > ~/.translate/de-en.ISO-8859-1.vok
+#f5# Translates a word
+trans() {
+ emulate -L zsh
+ case "$1" in
+ -[dD]*)
+ translate -l de-en $2
+ ;;
+ -[eE]*)
+ translate -l en-de $2
+ ;;
+ *)
+ echo "Usage: $0 { -D | -E }"
+ echo " -D == German to English"
+ echo " -E == English to German"
+ esac
+}
+
+# Usage: simple-extract <file>
+# Using option -d deletes the original archive file.
+#f5# Smart archive extractor
+simple-extract() {
+ emulate -L zsh
+ setopt extended_glob noclobber
+ local DELETE_ORIGINAL DECOMP_CMD USES_STDIN USES_STDOUT GZTARGET WGET_CMD
+ local RC=0
+ zparseopts -D -E "d=DELETE_ORIGINAL"
+ for ARCHIVE in "${@}"; do
+ case $ARCHIVE in
+ *.(tar.bz2|tbz2|tbz))
+ DECOMP_CMD="tar -xvjf -"
+ USES_STDIN=true
+ USES_STDOUT=false
+ ;;
+ *.(tar.gz|tgz))
+ DECOMP_CMD="tar -xvzf -"
+ USES_STDIN=true
+ USES_STDOUT=false
+ ;;
+ *.(tar.xz|txz|tar.lzma))
+ DECOMP_CMD="tar -xvJf -"
+ USES_STDIN=true
+ USES_STDOUT=false
+ ;;
+ *.tar)
+ DECOMP_CMD="tar -xvf -"
+ USES_STDIN=true
+ USES_STDOUT=false
+ ;;
+ *.rar)
+ DECOMP_CMD="unrar x"
+ USES_STDIN=false
+ USES_STDOUT=false
+ ;;
+ *.lzh)
+ DECOMP_CMD="lha x"
+ USES_STDIN=false
+ USES_STDOUT=false
+ ;;
+ *.7z)
+ DECOMP_CMD="7z x"
+ USES_STDIN=false
+ USES_STDOUT=false
+ ;;
+ *.(zip|jar))
+ DECOMP_CMD="unzip"
+ USES_STDIN=false
+ USES_STDOUT=false
+ ;;
+ *.deb)
+ DECOMP_CMD="ar -x"
+ USES_STDIN=false
+ USES_STDOUT=false
+ ;;
+ *.bz2)
+ DECOMP_CMD="bzip2 -d -c -"
+ USES_STDIN=true
+ USES_STDOUT=true
+ ;;
+ *.(gz|Z))
+ DECOMP_CMD="gzip -d -c -"
+ USES_STDIN=true
+ USES_STDOUT=true
+ ;;
+ *.(xz|lzma))
+ DECOMP_CMD="xz -d -c -"
+ USES_STDIN=true
+ USES_STDOUT=true
+ ;;
+ *)
+ print "ERROR: '$ARCHIVE' has unrecognized archive type." >&2
+ RC=$((RC+1))
+ continue
+ ;;
+ esac
+
+ if ! check_com ${DECOMP_CMD[(w)1]}; then
+ echo "ERROR: ${DECOMP_CMD[(w)1]} not installed." >&2
+ RC=$((RC+2))
+ continue
+ fi
+
+ GZTARGET="${ARCHIVE:t:r}"
+ if [[ -f $ARCHIVE ]] ; then
+
+ print "Extracting '$ARCHIVE' ..."
+ if $USES_STDIN; then
+ if $USES_STDOUT; then
+ ${=DECOMP_CMD} < "$ARCHIVE" > $GZTARGET
+ else
+ ${=DECOMP_CMD} < "$ARCHIVE"
+ fi
+ else
+ if $USES_STDOUT; then
+ ${=DECOMP_CMD} "$ARCHIVE" > $GZTARGET
+ else
+ ${=DECOMP_CMD} "$ARCHIVE"
+ fi
+ fi
+ [[ $? -eq 0 && -n "$DELETE_ORIGINAL" ]] && rm -f "$ARCHIVE"
+
+ elif [[ "$ARCHIVE" == (#s)(https|http|ftp)://* ]] ; then
+ if check_com curl; then
+ WGET_CMD="curl -L -k -s -o -"
+ elif check_com wget; then
+ WGET_CMD="wget -q -O - --no-check-certificate"
+ else
+ print "ERROR: neither wget nor curl is installed" >&2
+ RC=$((RC+4))
+ continue
+ fi
+ print "Downloading and Extracting '$ARCHIVE' ..."
+ if $USES_STDIN; then
+ if $USES_STDOUT; then
+ ${=WGET_CMD} "$ARCHIVE" | ${=DECOMP_CMD} > $GZTARGET
+ RC=$((RC+$?))
+ else
+ ${=WGET_CMD} "$ARCHIVE" | ${=DECOMP_CMD}
+ RC=$((RC+$?))
+ fi
+ else
+ if $USES_STDOUT; then
+ ${=DECOMP_CMD} =(${=WGET_CMD} "$ARCHIVE") > $GZTARGET
+ else
+ ${=DECOMP_CMD} =(${=WGET_CMD} "$ARCHIVE")
+ fi
+ fi
+
+ else
+ print "ERROR: '$ARCHIVE' is neither a valid file nor a supported URI." >&2
+ RC=$((RC+8))
+ fi
+ done
+ return $RC
+}
+
+__archive_or_uri()
+{
+ _alternative \
+ 'files:Archives:_files -g "*.(#l)(tar.bz2|tbz2|tbz|tar.gz|tgz|tar.xz|txz|tar.lzma|tar|rar|lzh|7z|zip|jar|deb|bz2|gz|Z|xz|lzma)"' \
+ '_urls:Remote Archives:_urls'
+}
+
+_simple_extract()
+{
+ _arguments \
+ '-d[delete original archivefile after extraction]' \
+ '*:Archive Or Uri:__archive_or_uri'
+}
+compdef _simple_extract simple-extract
+alias se=simple-extract
+
+#f5# Set all ulimit parameters to \kbd{unlimited}
+allulimit() {
+ ulimit -c unlimited
+ ulimit -d unlimited
+ ulimit -f unlimited
+ ulimit -l unlimited
+ ulimit -n unlimited
+ ulimit -s unlimited
+ ulimit -t unlimited
+}
+
+#f5# Change the xterm title from within GNU-screen
+xtrename() {
+ emulate -L zsh
+ if [[ $1 != "-f" ]] ; then
+ if [[ -z ${DISPLAY} ]] ; then
+ printf 'xtrename only makes sense in X11.\n'
+ return 1
+ fi
+ else
+ shift
+ fi
+ if [[ -z $1 ]] ; then
+ printf 'usage: xtrename [-f] "title for xterm"\n'
+ printf ' renames the title of xterm from _within_ screen.\n'
+ printf ' also works without screen.\n'
+ printf ' will not work if DISPLAY is unset, use -f to override.\n'
+ return 0
+ fi
+ print -n "\eP\e]0;${1}\C-G\e\\"
+ return 0
+}
+
+# Create small urls via http://goo.gl using curl(1).
+# API reference: https://code.google.com/apis/urlshortener/
+function zurl() {
+ emulate -L zsh
+ if [[ -z $1 ]]; then
+ print "USAGE: zurl <URL>"
+ return 1
+ fi
+
+ local PN url prog api json data
+ PN=$0
+ url=$1
+
+ # Prepend 'http://' to given URL where necessary for later output.
+ if [[ ${url} != http(s|)://* ]]; then
+ url='http://'${url}
+ fi
+
+ if check_com -c curl; then
+ prog=curl
+ else
+ print "curl is not available, but mandatory for ${PN}. Aborting."
+ return 1
+ fi
+ api='https://www.googleapis.com/urlshortener/v1/url'
+ contenttype="Content-Type: application/json"
+ json="{\"longUrl\": \"${url}\"}"
+ data=$($prog --silent -H ${contenttype} -d ${json} $api)
+ # Match against a regex and print it
+ if [[ $data =~ '"id": "(http://goo.gl/[[:alnum:]]+)"' ]]; then
+ print $match;
+ fi
+}
+
+#f2# Find history events by search pattern and list them by date.
+whatwhen() {
+ emulate -L zsh
+ local usage help ident format_l format_s first_char remain first last
+ usage='USAGE: whatwhen [options] <searchstring> <search range>'
+ help='Use `whatwhen -h'\'' for further explanations.'
+ ident=${(l,${#${:-Usage: }},, ,)}
+ format_l="${ident}%s\t\t\t%s\n"
+ format_s="${format_l//(\\t)##/\\t}"
+ # Make the first char of the word to search for case
+ # insensitive; e.g. [aA]
+ first_char=[${(L)1[1]}${(U)1[1]}]
+ remain=${1[2,-1]}
+ # Default search range is `-100'.
+ first=${2:-\-100}
+ # Optional, just used for `<first> <last>' given.
+ last=$3
+ case $1 in
+ ("")
+ printf '%s\n\n' 'ERROR: No search string specified. Aborting.'
+ printf '%s\n%s\n\n' ${usage} ${help} && return 1
+ ;;
+ (-h)
+ printf '%s\n\n' ${usage}
+ print 'OPTIONS:'
+ printf $format_l '-h' 'show help text'
+ print '\f'
+ print 'SEARCH RANGE:'
+ printf $format_l "'0'" 'the whole history,'
+ printf $format_l '-<n>' 'offset to the current history number; (default: -100)'
+ printf $format_s '<[-]first> [<last>]' 'just searching within a give range'
+ printf '\n%s\n' 'EXAMPLES:'
+ printf ${format_l/(\\t)/} 'whatwhen grml' '# Range is set to -100 by default.'
+ printf $format_l 'whatwhen zsh -250'
+ printf $format_l 'whatwhen foo 1 99'
+ ;;
+ (\?)
+ printf '%s\n%s\n\n' ${usage} ${help} && return 1
+ ;;
+ (*)
+ # -l list results on stout rather than invoking $EDITOR.
+ # -i Print dates as in YYYY-MM-DD.
+ # -m Search for a - quoted - pattern within the history.
+ fc -li -m "*${first_char}${remain}*" $first $last
+ ;;
+ esac
+}
+
+# mercurial related stuff
+if check_com -c hg ; then
+ # gnu like diff for mercurial
+ # http://www.selenic.com/mercurial/wiki/index.cgi/TipsAndTricks
+ #f5# GNU like diff for mercurial
+ hgdi() {
+ emulate -L zsh
+ for i in $(hg status -marn "$@") ; diff -ubwd <(hg cat "$i") "$i"
+ }
+
+ # build debian package
+ #a2# Alias for \kbd{hg-buildpackage}
+ alias hbp='hg-buildpackage'
+
+ # execute commands on the versioned patch-queue from the current repos
+ alias mq='hg -R $(readlink -f $(hg root)/.hg/patches)'
+
+ # diffstat for specific version of a mercurial repository
+ # hgstat => display diffstat between last revision and tip
+ # hgstat 1234 => display diffstat between revision 1234 and tip
+ #f5# Diffstat for specific version of a mercurial repos
+ hgstat() {
+ emulate -L zsh
+ [[ -n "$1" ]] && hg diff -r $1 -r tip | diffstat || hg export tip | diffstat
+ }
+
+fi # end of check whether we have the 'hg'-executable
+
+# grml-small cleanups
+
+# The following is used to remove zsh-config-items that do not work
+# in grml-small by default.
+# If you do not want these adjustments (for whatever reason), set
+# $GRMLSMALL_SPECIFIC to 0 in your .zshrc.pre file (which this configuration
+# sources if it is there).
+
+if (( GRMLSMALL_SPECIFIC > 0 )) && isgrmlsmall ; then
+
+ unset abk[V]
+ unalias 'V' &> /dev/null
+ unfunction vman &> /dev/null
+ unfunction viless &> /dev/null
+ unfunction 2html &> /dev/null
+
+ # manpages are not in grmlsmall
+ unfunction manzsh &> /dev/null
+ unfunction man2 &> /dev/null
+
+fi
+
+zrclocal
+
+## genrefcard.pl settings
+
+### doc strings for external functions from files
+#m# f5 grml-wallpaper() Sets a wallpaper (try completion for possible values)