+
+ #f1# Provides useful information 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) # Files modified up to a day ago
+ print *(a1) # Files accessed a day ago
+ print *(@) # Just symlinks
+ print *(Lk+50) # Files bigger than 50 kilobytes
+ print *(Lk-50) # Files smaller than 50 kilobytes
+ print **/*.c # All *.c files recursively starting in \$PWD
+ print **/*.c~file.c # Same as above, but excluding 'file.c'
+ print (foo|bar).* # Files starting with 'foo' or 'bar'
+ print *~*.* # All Files that do not contain a dot
+ chmod 644 *(.^x) # make all plain non-executable files publically readable
+ print -l *(.c|.h) # Lists *.c and *.h
+ print **/*(g:users:) # Recursively match all files that are owned by group 'users'
+ echo /proc/*/cwd(:h:t:s/self//) # Analogous to >ps ax | awk '{print $1}'<"
+ }
+ alias help-zshglob=H-Glob
+
+ type -p qma &>/dev/null && alias ?='qma zshall'
+
+ # grep for running process, like: 'any vim'
+ any() {
+ if [ -z "$1" ] ; then
+ echo "any - grep for process(es) by keyword" >&2
+ echo "Usage: any <keyword>" >&2 ; return 1
+ else
+ local STRING=$1
+ local LENGTH=$(expr length $STRING)
+ local FIRSCHAR=$(echo $(expr substr $STRING 1 1))
+ local REST=$(echo $(expr substr $STRING 2 $LENGTH))
+ ps xauwww| grep "[$FIRSCHAR]$REST"
+ fi
+ }
+
+ # After resuming from suspend, system is paging heavily, leading to very bad interactivity.
+ # taken from $LINUX-KERNELSOURCE/Documentation/power/swsusp.txt
+ [ -r /proc/1/maps ] && deswap() {
+ print 'Reading /proc/[0-9]*/maps and sending output to /dev/null, this might take a while.'
+ cat $(sed -ne 's:.* /:/:p' /proc/[0-9]*/maps | sort -u | grep -v '^/dev/') > /dev/null
+ print 'Finished, running "swapoff -a; swapon -a" may also be useful.'
+ }
+
+ # print hex value of a number
+ hex() {
+ [ -n "$1" ] && printf "%x\n" $1 || { print 'Usage: hex <number-to-convert>' ; return 1 }
+ }
+
+ # calculate (or eval at all ;-)) with perl => p[erl-]eval
+ # hint: also take a look at zcalc -> 'autoload zcalc' -> 'man zshmodules | less -p MATHFUNC'
+ peval() {
+ [ -n "$1" ] && CALC="$*" || print "Usage: calc [expression]"
+ perl -e "print eval($CALC),\"\n\";"
+ }
+ functions peval &>/dev/null && alias calc=peval
+
+ # brltty seems to have problems with utf8 environment and/or font Uni3-Terminus16 under
+ # certain circumstances, so work around it, no matter which environment we have
+ brltty() {
+ if [ -z "$DISPLAY" ] ; then
+ consolechars -f /usr/share/consolefonts/default8x16.psf.gz
+ command brltty "$@"
+ else
+ command brltty "$@"
+ fi
+ }
+
+ # just press 'asdf' keys to toggle between dvorak and us keyboard layout
+ aoeu() {
+ echo -n 'Switching to us keyboard layout: '
+ [ -z "$DISPLAY" ] && $SUDO loadkeys us &>/dev/null || setxkbmap us &>/dev/null
+ echo 'Done'
+ }
+ asdf() {
+ echo -n 'Switching to dvorak keyboard layout: '
+ [ -z "$DISPLAY" ] && $SUDO loadkeys dvorak &>/dev/null || setxkbmap dvorak &>/dev/null
+ echo 'Done'
+ }
+ # just press 'asdf' key to toggle from neon layout to us keyboard layout
+ uiae() {
+ echo -n 'Switching to us keyboard layout: '
+ setxkbmap us && echo 'Done' || echo 'Failed'
+ }
+
+ # set up an ipv6 tunnel
+ ipv6-tunnel() {
+ case $1 in
+ start)
+ if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
+ print 'ipv6 tunnel already set up, nothing to be done.'
+ print 'execute: "ifconfig sit1 down ; ifconfig sit0 down" to remove ipv6-tunnel.' ; return 1
+ else
+ [ -n "$PUBLIC_IP" ] || local PUBLIC_IP=$(ifconfig $(route -n | awk '/^0\.0\.0\.0/{print $8; exit}') | \
+ awk '/inet addr:/ {print $2}' | tr -d 'addr:')
+ [ -n "$PUBLIC_IP" ] || { print 'No $PUBLIC_IP set and could not determine default one.' ; return 1 }
+ local IPV6ADDR=$(printf "2002:%02x%02x:%02x%02x:1::1" $(print ${PUBLIC_IP//./ }))
+ print -n "Setting up ipv6 tunnel $IPV6ADDR via ${PUBLIC_IP}: "
+ ifconfig sit0 tunnel ::192.88.99.1 up
+ ifconfig sit1 add "$IPV6ADDR" && print done || print failed
+ fi
+ ;;
+ status)
+ if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
+ print 'ipv6 tunnel available' ; return 0
+ else
+ print 'ipv6 tunnel not available' ; return 1
+ fi
+ ;;
+ stop)
+ if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
+ print -n 'Stopping ipv6 tunnel (sit0 + sit1): '
+ ifconfig sit1 down ; ifconfig sit0 down && print done || print failed
+ else
+ print 'No ipv6 tunnel found, nothing to be done.' ; return 1
+ fi
+ ;;
+ *)
+ print "Usage: ipv6-tunnel [start|stop|status]">&2 ; return 1
+ ;;
+ esac
+ }
+
+ # run dhclient for wireless device
+ iwclient() {
+ salias dhclient "$(wavemon -d | awk '/device/{print $2}')"
+ }
+
+ # spawn a minimally set up ksh - useful if you want to umount /usr/.
+ minimal-shell() {
+ exec env -i ENV="/etc/minimal-shellrc" HOME="$HOME" TERM="$TERM" ksh
+ }
+
+ # Switching shell safely and efficiently? http://www.zsh.org/mla/workers/2001/msg02410.html
+ # bash() {
+ # NO_SWITCH="yes" command bash "$@"
+ # }
+ # restart () {
+ # exec $SHELL $SHELL_ARGS "$@"
+ # }
+
+# }}}
+
+# log out? set timeout in seconds {{{
+# TMOUT=1800
+# do not log out in some specific terminals:
+# if [[ "${TERM}" == ([Exa]term*|rxvt|dtterm|screen*) ]]; then
+# unset TMOUT
+# fi
+# }}}
+
+# {{{ make sure our environment is clean regarding colors
+ for color in BLUE RED GREEN CYAN WHITE ; unset $color