echo "$t"
builtin cd "$t"
}
-#f5# Unified diff to timestamped outputfile
-mdiff() {
- diff -udrP "$1" "$2" > diff.`date "+%Y-%m-%d"`."$1"
-}
#f5# Create directory under cursor or the selected area
# Press ctrl-xM to create the directory under the cursor or the selected area.
#k# mkdir -p <dir> from string under cursor or marked area
zle -N inplaceMkDirs && bindkey '^XM' inplaceMkDirs
-#f5# Memory overview
-memusage() {
- ps aux | awk '{if (NR > 1) print $5; if (NR > 2) print "+"} END { print "p" }' | dc
-}
-#f5# Show contents of gzipped tar file
-shtar() {
- emulate -L zsh
- gunzip -c $1 | tar -tf - -- | $PAGER
-}
-#f5# Show contents of zip file
-shzip() {
- emulate -L zsh
- unzip -l $1 | $PAGER
-}
-#f5# Unified diff
-udiff() {
- emulate -L zsh
- diff -urd $* | egrep -v "^Only in |^Binary files "
-}
-#f5# (Mis)use \kbd{vim} as \kbd{less}
-viless() {
- emulate -L zsh
- vim --cmd 'let no_plugin_maps = 1' -c "so \$VIMRUNTIME/macros/less.vim" "${@:--}"
-}
-
-# Function Usage: uopen $URL/$file
-#f5# Download a file and display it locally
-uopen() {
- emulate -L zsh
- if ! [[ -n "$1" ]] ; then
- print "Usage: uopen \$URL/\$file">&2
- return 1
- else
- FILE=$1
- MIME=$(curl --head $FILE | grep Content-Type | cut -d ' ' -f 2 | cut -d\; -f 1)
- MIME=${MIME%$'\r'}
- curl $FILE | see ${MIME}:-
- fi
-}
-
# Function Usage: doc packagename
#f5# \kbd{cd} to /usr/share/doc/\textit{package}
doc() {
cd ~/shots ; sleep 5; import -window root shot_`date --iso-8601=m`.jpg
}
-# list images only
-limg() {
- local -a images
- images=( *.{jpg,gif,png}(.N) )
-
- if [[ $#images -eq 0 ]] ; then
- print "No image files found"
- else
- ls "$images[@]"
- fi
-}
-
-#f5# Create PDF file from source code
-makereadable() {
- emulate -L zsh
- output=$1
- shift
- a2ps --medium A4dj -E -o $output $*
- ps2pdf $output
-}
-
-# zsh with perl-regex - use it e.g. via:
-# regcheck '\s\d\.\d{3}\.\d{3} Euro' ' 1.000.000 Euro'
-#f5# Checks whether a regex matches or not.\\&\quad Example: \kbd{regcheck '.\{3\} EUR' '500 EUR'}
-regcheck() {
- emulate -L zsh
- zmodload -i zsh/pcre
- pcre_compile $1 && \
- pcre_match $2 && echo "regex matches" || echo "regex does not match"
-}
-
#f5# List files which have been accessed within the last {\it n} days, {\it n} defaults to 1
accessed() {
emulate -L zsh
# modified() was named new() in earlier versions, add an alias for backwards compatibility
check_com new || alias new=modified
-#f5# Grep in history
-greph() {
- emulate -L zsh
- history 0 | grep $1
-}
# use colors when GNU grep with color-support
#a2# Execute \kbd{grep -{}-color=auto}
(grep --help 2>/dev/null |grep -- --color) >/dev/null && alias grep='grep --color=auto'
#a2# Execute \kbd{grep -i -{}-color=auto}
alias GREP='grep -i --color=auto'
-#f5# Watch manpages in a stretched style
-man2() { PAGER='dash -c "sed G | /usr/bin/less"' command man "$@" ; }
-
-# usage example: 'lcheck strcpy'
-#f5# Find out which libs define a symbol
-lcheck() {
- if [[ -n "$1" ]] ; then
- nm -go /usr/lib/lib*.a 2>/dev/null | grep ":[[:xdigit:]]\{8\} . .*$1"
- else
- echo "Usage: lcheck <function>" >&2
- fi
-}
-
-#f5# Clean up directory - remove well known tempfiles
-purge() {
- emulate -L zsh
- setopt HIST_SUBST_PATTERN
- local -a TEXTEMPFILES GHCTEMPFILES PYTEMPFILES FILES
- TEXTEMPFILES=(*.tex(N:s/%tex/'(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(N)'/))
- GHCTEMPFILES=(*.(hs|lhs)(N:r:s/%/'.(hi|hc|(p|u|s)_(o|hi))(N)'/))
- PYTEMPFILES=(*.py(N:s/%py/'(pyc|pyo)(N)'/))
- LONELY_MOOD_FILES=((*.mood)(.NDe:'local -a AF;AF=( ${${REPLY#.}%mood}(mp3|flac|ogg|asf|wmv|aac)(N) ); [[ -z "$AF" ]]':))
- ZSH_COMPILED=(*.zwc(.NDe:'[[ -f ${REPLY%.zwc} && ${REPLY%.zwc} -nt ${REPLY} ]]':))
- FILES=(*~(.N) \#*\#(.N) *.o(.N) a.out(.N) (*.|)core(.N) *.cmo(.N) *.cmi(.N) .*.swp(.N) *.(orig|rej)(.DN) *.dpkg-(old|dist|new)(DN) ._(cfg|mrg)[0-9][0-9][0-9][0-9]_*(N) ${~TEXTEMPFILES} ${~GHCTEMPFILES} ${~PYTEMPFILES} ${LONELY_MOOD_FILES} ${ZSH_COMPILED} )
- local NBFILES=${#FILES}
- local CURDIRSUDO=""
- [[ ! -w ./ ]] && CURDIRSUDO=$SUDO
- if [[ $NBFILES > 0 ]] ; then
- print -l $FILES
- local ans
- echo -n "Remove these files? [y/n] "
- read -q ans; echo
- if [[ $ans == "y" ]] ; then
- $CURDIRSUDO rm ${FILES}
- echo ">> $PWD purged, $NBFILES files removed"
- else
- echo "Ok. .. then not.."
- fi
- fi
-}
-
-#f5# show labels and uuids of disk devices
-if is439 && [[ -d /dev/disk/by-id/ ]]; then
- lsdisk() {
- emulate -L zsh
- setopt extendedglob
- local -a -U disks
- local -A mountinfo
- disks=( /dev/disk/by-id/*(@:A) )
- [[ -r /proc/mounts ]] && for cline ( "${(f)$(</proc/mounts)[@]}" ) mountinfo["${cline[(w)1]:A}"]="${cline[(w)2,-1]}"
- for dev in "$disks[@]"; do
- print ${fg_bold[red]}${dev}${reset_color} /dev/disk/by-label/*(@e/'[[ ${REPLY:A} == $dev ]] && REPLY=${fg[blue]}LABEL=${REPLY:t}${reset_color}'/N) /dev/disk/by-uuid/*(@e/'[[ ${REPLY:A} == $dev ]] && REPLY=${fg[green]}UUID=${REPLY:t}${reset_color}'/N)
- [[ -n "${mountinfo["$dev"]}" ]] && print -f " Mount: %s -t %s -o %s\n" ${mountinfo["$dev"][(w)1]} ${mountinfo["$dev"][(w)2]} "${mountinfo["$dev"][(w)3,-5]}"
- for sysdevsize ( /sys/block/${dev:t}/size(N) /sys/block/${${dev:t}%%<->}/${dev:t}/size(N) ) \
- print -f " Size: %.3f GiB (%d Byte)\n" $(($(<$sysdevsize)/(2.0*1024.0*1024.0))) $(($(<$sysdevsize)*512))
-
- print -f " Id: %s\n" /dev/disk/by-id/*(@e/'[[ ${REPLY:A} == $dev ]]'/N:t)
- done
- }
-fi
-
-#f5# run command or function in a list of directories
-rundirs() {
- local d CMD STARTDIR=$PWD
- CMD=$1; shift
- ( for d ($@) {cd -q $d && { print cd $d; ${(z)CMD} ; cd -q $STARTDIR }} )
-}
-
# 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
esac
}
-#f5# List all occurrences of programm in current PATH
-plap() {
- emulate -L zsh
- if [[ $# = 0 ]] ; then
- echo "Usage: $0 program"
- echo "Example: $0 zsh"
- echo "Lists all occurrences of program in the current PATH."
- else
- ls -l ${^path}/*$1*(*N)
- fi
-}
-
-# Found in the mailinglistarchive from Zsh (IIRC ~1996)
-#f5# Select items for specific command(s) from history
-selhist() {
- emulate -L zsh
- local TAB=$'\t';
- (( $# < 1 )) && {
- echo "Usage: $0 command"
- return 1
- };
- cmd=(${(f)"$(grep -w $1 $HISTFILE | sort | uniq | pr -tn)"})
- print -l $cmd | less -F
- echo -n "enter number of desired command [1 - $(( ${#cmd[@]} - 1 ))]: "
- local answer
- read answer
- print -z "${cmd[$answer]#*$TAB}"
-}
-
-# Use vim to convert plaintext to HTML
-#f5# Transform files to html with highlighting
-2html() {
- emulate -L zsh
- vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 &>/dev/null
-}
-
# Usage: simple-extract <file>
# Using option -d deletes the original archive file.
#f5# Smart archive extractor
fi
}
-# It's shameless stolen from <http://www.vim.org/tips/tip.php?tip_id=167>
-#f5# Use \kbd{vim} as your manpage reader
-vman() {
- emulate -L zsh
- if (( ${#argv} == 0 )); then
- printf 'usage: vman <topic>\n'
- return 1
- fi
- man "$@" | col -b | view -c 'set ft=man nomod nolist' -
-}
-
-# function readme() { $PAGER -- (#ia3)readme* }
-#f5# View all README-like files in current directory in pager
-readme() {
- emulate -L zsh
- setopt extendedglob
- local files
- files=(./(#i)*(read*me|lue*m(in|)ut|lies*mich)*(NDr^/=p%))
- if (($#files)) ; then
- $PAGER $files
- else
- print 'No README files.'
- fi
-}
-
-# function ansi-colors()
-#f5# Display ANSI colors
-ansi-colors() {
- typeset esc="\033[" line1 line2
- echo " _ _ _40 _ _ _41_ _ _ _42 _ _ 43_ _ _ 44_ _ _45 _ _ _ 46_ _ _ 47_ _ _ 49_ _"
- for fore in 30 31 32 33 34 35 36 37; do
- line1="$fore "
- line2=" "
- for back in 40 41 42 43 44 45 46 47 49; do
- line1="${line1}${esc}${back};${fore}m Normal ${esc}0m"
- line2="${line2}${esc}${back};${fore};1m Bold ${esc}0m"
- done
- echo -e "$line1\n$line2"
- done
-}
-
-#f5# Find all files in \$PATH with setuid bit set
-suidfind() { ls -latg $path | grep '^...s' }
-
# TODO: So, this is the third incarnation of this function!?
#f5# Reload given functions
refunc() {
}
compdef _functions refunc
-# a small check to see which DIR is located on which server/partition.
-# stolen and modified from Sven's zshrc.forall
-#f5# Report diskusage of a directory
-dirspace() {
- emulate -L zsh
- if [[ -n "$1" ]] ; then
- for dir in "$@" ; do
- if [[ -d "$dir" ]] ; then
- ( cd $dir; echo "-<$dir>"; du -shx .; echo);
- else
- echo "warning: $dir does not exist" >&2
- fi
- done
- else
- for dir in $path; do
- if [[ -d "$dir" ]] ; then
- ( cd $dir; echo "-<$dir>"; du -shx .; echo);
- else
- echo "warning: $dir does not exist" >&2
- fi
- done
- fi
-}
-
-# % slow_print `cat /etc/passwd`
-#f5# Slowly print out parameters
-slow_print() {
- for argument in "$@" ; do
- for ((i = 1; i <= ${#1} ;i++)) ; do
- print -n "${argument[i]}"
- sleep 0.08
- done
- print -n " "
- done
- print ""
-}
-
-#f5# Show some status info
-status() {
- print
- print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")
- print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)"
- print "Term..: $TTY ($TERM), ${BAUD:+$BAUD bauds, }$COLUMNS x $LINES chars"
- print "Login.: $LOGNAME (UID = $EUID) on $HOST"
- print "System: $(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)"
- print "Uptime:$(uptime)"
- print
-}
-
#f5# Set all ulimit parameters to \kbd{unlimited}
allulimit() {
ulimit -c unlimited