- 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
-
-#v1# set number of lines to display per page
-HELP_LINES_PER_PAGE=20
-#v1# set location of help-zle cache file
-HELP_ZLE_CACHE_FILE=~/.cache/zsh_help_zle_lines.zsh
-#f1# helper function for help-zle, actually generates the help text
-help_zle_parse_keybindings()
-{
- emulate -L zsh
- setopt extendedglob
- unsetopt ksharrays #indexing starts at 1
-
- #v1# choose files that help-zle will parse for keybindings
- ((${+HELPZLE_KEYBINDING_FILES})) || HELPZLE_KEYBINDING_FILES=( /etc/zsh/zshrc ~/.zshrc.pre ~/.zshrc ~/.zshrc.local )
-
- if [[ -r $HELP_ZLE_CACHE_FILE ]]; then
- local load_cache=0
- for f ($KEYBINDING_FILES) [[ $f -nt $HELP_ZLE_CACHE_FILE ]] && load_cache=1
- [[ $load_cache -eq 0 ]] && . $HELP_ZLE_CACHE_FILE && return
- fi
-
- #fill with default keybindings, possibly to be overwriten in a file later
- #Note that due to zsh inconsistency on escaping assoc array keys, we encase the key in '' which we will remove later
- local -A help_zle_keybindings
- help_zle_keybindings['<Ctrl>@']="set MARK"
- help_zle_keybindings['<Ctrl>X<Ctrl>J']="vi-join lines"
- help_zle_keybindings['<Ctrl>X<Ctrl>B']="jump to matching brace"
- help_zle_keybindings['<Ctrl>X<Ctrl>U']="undo"
- help_zle_keybindings['<Ctrl>_']="undo"
- help_zle_keybindings['<Ctrl>X<Ctrl>F<c>']="find <c> in cmdline"
- help_zle_keybindings['<Ctrl>A']="goto beginning of line"
- help_zle_keybindings['<Ctrl>E']="goto end of line"
- help_zle_keybindings['<Ctrl>t']="transpose charaters"
- help_zle_keybindings['<Alt>T']="transpose words"
- help_zle_keybindings['<Alt>s']="spellcheck word"
- help_zle_keybindings['<Ctrl>K']="backward kill buffer"
- help_zle_keybindings['<Ctrl>U']="forward kill buffer"
- help_zle_keybindings['<Ctrl>y']="insert previously killed word/string"
- help_zle_keybindings["<Alt>'"]="quote line"
- help_zle_keybindings['<Alt>"']="quote from mark to cursor"
- help_zle_keybindings['<Alt><arg>']="repeat next cmd/char <arg> times (<Alt>-<Alt>1<Alt>0a -> -10 times 'a')"
- help_zle_keybindings['<Alt>U']="make next word Uppercase"
- help_zle_keybindings['<Alt>l']="make next word lowercase"
- help_zle_keybindings['<Ctrl>Xd']="preview expansion under cursor"
- help_zle_keybindings['<Alt>q']="push current CL into background, freeing it. Restore on next CL"
- help_zle_keybindings['<Alt>.']="insert (and interate through) last word from prev CLs"
- help_zle_keybindings['<Alt>,']="complete word from newer history (consecutive hits)"
- help_zle_keybindings['<Alt>m']="repeat last typed word on current CL"
- help_zle_keybindings['<Ctrl>V']="insert next keypress symbol literally (e.g. for bindkey)"
- help_zle_keybindings['!!:n*<Tab>']="insert last n arguments of last command"
- help_zle_keybindings['!!:n-<Tab>']="insert arguments n..N-2 of last command (e.g. mv s s d)"
- help_zle_keybindings['<Alt>H']="run help on current command"
-
- #init global variables
- unset help_zle_lines help_zle_sln
- typeset -g -a help_zle_lines
- typeset -g help_zle_sln=1
-
- local k v
- local lastkeybind_desc contents #last description starting with #k# that we found
- local num_lines_elapsed=0 #number of lines between last description and keybinding
- #search config files in the order they a called (and thus the order in which they overwrite keybindings)
- for f in $HELPZLE_KEYBINDING_FILES; do
- [[ -r "$f" ]] || continue #not readable ? skip it
- contents="$(<$f)"
- for cline in "${(f)contents}"; do
- #zsh pattern: matches lines like: #k# ..............
- if [[ "$cline" == (#s)[[:space:]]#\#k\#[[:space:]]##(#b)(*)[[:space:]]#(#e) ]]; then
- lastkeybind_desc="$match[*]"
- num_lines_elapsed=0
- #zsh pattern: matches lines that set a keybinding using bindkey or compdef -k
- # ignores lines that are commentend out
- # grabs first in '' or "" enclosed string with length between 1 and 6 characters
- elif [[ "$cline" == [^#]#(bindkey|compdef -k)[[:space:]](*)(#b)(\"((?)(#c1,6))\"|\'((?)(#c1,6))\')(#B)(*) ]]; then
- #description prevously found ? description not more than 2 lines away ? keybinding not empty ?
- if [[ -n $lastkeybind_desc && $num_lines_elapsed -lt 2 && -n $match[1] ]]; then
- #substitute keybinding string with something readable
- k=${${${${${${${match[1]/\\e\^h/<Alt><BS>}/\\e\^\?/<Alt><BS>}/\\e\[5~/<PageUp>}/\\e\[6~/<PageDown>}//(\\e|\^\[)/<Alt>}//\^/<Ctrl>}/3~/<Alt><Del>}
- #put keybinding in assoc array, possibly overwriting defaults or stuff found in earlier files
- #Note that we are extracting the keybinding-string including the quotes (see Note at beginning)
- help_zle_keybindings[${k}]=$lastkeybind_desc
- fi
- lastkeybind_desc=""
- else
- ((num_lines_elapsed++))
- fi
- done
- done
- unset contents
- #calculate length of keybinding column
- local kstrlen=0
- for k (${(k)help_zle_keybindings[@]}) ((kstrlen < ${#k})) && kstrlen=${#k}
- #convert the assoc array into preformated lines, which we are able to sort
- for k v in ${(kv)help_zle_keybindings[@]}; do
- #pad keybinding-string to kstrlen chars and remove outermost characters (i.e. the quotes)
- help_zle_lines+=("${(r:kstrlen:)k[2,-2]}${v}")
- done
- #sort lines alphabetically
- help_zle_lines=("${(i)help_zle_lines[@]}")
- [[ -d ${HELP_ZLE_CACHE_FILE:h} ]] || mkdir -p "${HELP_ZLE_CACHE_FILE:h}"
- echo "help_zle_lines=(${(q)help_zle_lines[@]})" >| $HELP_ZLE_CACHE_FILE
- zcompile $HELP_ZLE_CACHE_FILE
-}
-typeset -g help_zle_sln
-typeset -g -a help_zle_lines
-
-#f1# Provides (partially autogenerated) help on keybindings and the zsh line editor
-help-zle()
-{
- emulate -L zsh
- unsetopt ksharrays #indexing starts at 1
- #help lines already generated ? no ? then do it
- [[ ${+functions[help_zle_parse_keybindings]} -eq 1 ]] && {help_zle_parse_keybindings && unfunction help_zle_parse_keybindings}
- #already displayed all lines ? go back to the start
- [[ $help_zle_sln -gt ${#help_zle_lines} ]] && help_zle_sln=1
- local sln=$help_zle_sln
- #note that help_zle_sln is a global var, meaning we remember the last page we viewed
- help_zle_sln=$((help_zle_sln + HELP_LINES_PER_PAGE))
- zle -M "${(F)help_zle_lines[sln,help_zle_sln-1]}"
-}
-#k# display help for keybindings and ZLE (cycle pages with consecutive use)
-zle -N help-zle && bindkey '^Xz' help-zle
-
-check_com -c qma && alias ?='qma zshall'
-
-# grep for running process, like: 'any vim'
-any() {
- emulate -L zsh
- unsetopt KSH_ARRAYS
- if [[ -z "$1" ]] ; then
- echo "any - grep for process(es) by keyword" >&2
- echo "Usage: any <keyword>" >&2 ; return 1
- else
- ps xauwww | grep -i --color=auto "[${1[1]}]${1[2,-1]}"
- 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() {
- emulate -L zsh
- [[ -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
-
-# 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() {
- emulate -L zsh
- 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() {
- sudo dhclient "$(wavemon -d | awk '/device/{print $3}')"