X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Fskel%2F.zshrc;h=aa1b3e3a83f4ad003c805e46103d7578632971b5;hb=222006c939694a8d6f20543cfb1d24a37e74e5de;hp=ea9f6bd97271abd3ab8b5ef7be2f62f0de7bea26;hpb=44caa64f88f6786d44c5e3c95d1e12c5e5e0890e;p=grml-etc-core.git diff --git a/etc/skel/.zshrc b/etc/skel/.zshrc index ea9f6bd..aa1b3e3 100644 --- a/etc/skel/.zshrc +++ b/etc/skel/.zshrc @@ -3,7 +3,7 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Fre Nov 24 23:08:52 CET 2006 [mika] +# Latest change: Don Mai 17 15:08:21 CEST 2007 [mika] ################################################################################ # source ~/.zshrc.global {{{ @@ -15,6 +15,11 @@ fi # }}} +# autoloading stuff {{{ + # associate types and extensions: + autoload zsh-mime-setup && zsh-mime-setup +# }}} + # completion system {{{ # just make sure it is loaded in this file too type compinit &>/dev/null || { autoload -U compinit && compinit } @@ -35,9 +40,9 @@ # set default browser if [ -z "$BROWSER" ] ; then if [ -n "$DISPLAY" ] ; then - [ -x =firefox ] && export BROWSER=firefox + [ -x $(which firefox) ] && export BROWSER=firefox else - [ -x =w3m ] && export BROWSER=w3m + [ -x $(which w3m) ] && export BROWSER=w3m fi fi (( ${+PAGER} )) || export PAGER="less" @@ -69,7 +74,8 @@ # These do not have to be at the beginning of the command line. # Avoid typing cd ../../ for going two dirs down and so on # Usage, e.g.: "$ cd ...' or just '$ ...' with 'setopt auto_cd' -# Notice: deactivated by 061112 by default, use another approach - see 'power completion' +# Notice: deactivated by 061112 by default, we use another approach +# known as "power completion / abbreviation expansion" # alias -g '...'='../..' # alias -g '....'='../../..' # alias -g BG='& exit' @@ -87,91 +93,6 @@ # alias -g S='| sort' # alias -g T='|tail' # alias -g V='| vim -' - -# power completion, see http://zshwiki.org/home/examples/zleiab -# less risky than the global aliases but powerful as well -# just type the abbreviation key and afterwards ',.' to expand it - declare -A abk - setopt extendedglob - setopt interactivecomments - abk=( - # key # value - 'C' '| wc -l' - '...' '../..' - '....' '../../..' - 'BG' '& exit' - 'C' '|wc -l' - 'G' '|& grep --color=auto' - 'H' '|head' - 'Hl' ' --help |& less -r' - 'L' '|less' - 'LL' '|& less -r' - 'M' '|most' - 'N' '&>/dev/null' - 'R' '| tr A-z N-za-m' - 'SL' '| sort | less' - 'S' '| sort -u' - 'T' '|tail' - 'V' '|& vim -' - 'hide' "echo -en '\033]50;nil2\007'" - 'tiny' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-80-*-*-c-*-iso8859-15\007"' - 'small' 'echo -en "\033]50;6x10\007"' - 'medium' 'echo -en "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-15\007"' - 'default' 'echo -e "\033]50;-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-15\007"' - 'large' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-150-*-*-c-*-iso8859-15\007"' - 'huge' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-210-*-*-c-*-iso8859-15\007"' - 'smartfont' 'echo -en "\033]50;-artwiz-smoothansi-*-*-*-*-*-*-*-*-*-*-*-*\007"' - 'semifont' 'echo -en "\033]50;-misc-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-iso8859-15\007"' - 'da' 'du -sch' - 'j' 'jobs -l' - 'u' 'translate -i' - 'co' "./configure && make && sudo make install" - 'CH' "./configure --help" - 'conkeror' 'firefox -chrome chrome://conkeror/content' - 'dir' 'ls -lSrah' - 'lad' $'ls -d .*(/)\n# only show dot-directories' - 'lsa' $'ls -a .*(.)\n# only show dot-files' - 'lss' $'ls -l *(s,S,t)\n# only files with setgid/setuid/sticky flag' - 'lsl' $'ls -l *(@[1,10])\n# only symlinks' - 'lsx' $'ls -l *(*[1,10])\n# only executables' - 'lsw' $'ls -ld *(R,W,X.^ND/)\n# world-{readable,writable,executable} files' - 'lsbig' $'ls -flh *(.OL[1,10])\n# display the biggest files' - 'lsd' $'ls -d *(/)\n# only show directories' - 'lse' $'ls -d *(/^F)\n# only show empty directories' - 'lsnew' $'ls -rl *(D.om[1,10])\n# display the newest files' - 'lsold' $'ls -rtlh *(D.om[-11,-1])\n # display the oldest files' - 'lssmall' $'ls -Srl *(.oL[1,10])\n# display the smallest files' - 'rw-' 'chmod 600' - '600' 'chmod u+rw-x,g-rwx,o-rwx' - 'rwx' 'chmod u+rwx' - '700' 'chmod u+rwx,g-rwx,o-rwx' - 'r--' 'chmod u+r-wx,g-rwx,o-rwx' - '644' $'chmod u+rw-x,g+r-wx,o+r-wx\n # 4=r,2=w,1=x' - '755' 'chmod u+rwx,g+r-w+x,o+r-w+x' - 'md' 'mkdir -p ' - 'cmplayer' 'mplayer -vo -fs -zoom fbdev' - 'fbmplayer' 'mplayer -vo -fs -zoom fbdev' - 'fblinks' 'links2 -driver fb' - 'insecssh' 'ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"' - 'fori' 'for i ({..}) { }' - 'cx' 'chmod +x' - 'e' 'print -l' - 'se' 'setopt interactivecomments' - 'va' 'valac --vapidir=../vapi/ --pkg=gtk+-2.0 gtktest.vala' - 'fb2' '=mplayer -vo fbdev -fs -zoom 1>/dev/null -xy 2' - 'fb3' '=mplayer -vo fbdev -fs -zoom 1>/dev/null -xy 3' - 'ci' 'centericq' - 'D' 'export DISPLAY=:0.0' - 'mp' 'mplayer -vo xv -fs -zoom' - ) - globalias () { - local MATCH - matched_chars='[.-|_a-zA-Z0-9]#' - LBUFFER=${LBUFFER%%(#m)[.-|_a-zA-Z0-9]#} - LBUFFER+=${abk[$MATCH]:-$MATCH} - } - zle -N globalias - bindkey ",." globalias # }}} ## aliases {{{ @@ -204,7 +125,7 @@ alias conkeror='firefox -chrome chrome://conkeror/content' # arch/tla stuff - if type -p tla >/dev/null 2>&1 ; then + if type -p tla &>/dev/null ; then alias tdi='tla what-changed --diffs | less' alias tbp='tla-buildpackage' alias tmi='tla archive-mirror' @@ -238,19 +159,32 @@ # console stuff alias cmplayer='mplayer -vo fbdev' -# alias fbmplayer='mplayer -vo fbdev' alias fbmplayer='mplayer -vo fbdev -fs -zoom' alias fblinks='links2 -driver fb' # ignore ~/.ssh/known_hosts entries # alias insecssh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" -o "PreferredAuthentications=keyboard-interactive"' alias insecssh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"' + alias insecscp='scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"' # use colors when browsing man pages (if not using pinfo or PAGER=most) [ -d ~/.terminfo/ ] && alias man='TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man' # check whether Debian's package management (dpkg) is running - alias check_dpkg_running="$SUDO dpkg_running" + salias check_dpkg_running="dpkg_running" + +# work around non utf8 capable software in utf environment + if [ -x /usr/bin/mrxvt ] ; then + isutfenv && [ -n "$LANG" ] && alias mrxvt="LANG=${LANG/(#b)(*)[.@]*/$match[1].iso885915} mrxvt" + fi + + if [ -x /usr/bin/aterm ] ; then + isutfenv && [ -n "$LANG" ] && alias aterm="LANG=${LANG/(#b)(*)[.@]*/$match[1].iso885915} aterm" + fi + + if [ -x /usr/bin/centericq ] ; then + isutfenv && [ -n "$LANG" ] && alias centericq="LANG=${LANG/(#b)(*)[.@]*/$match[1].iso885915} centericq" + fi # }}} ## useful functions {{{ @@ -267,7 +201,7 @@ cvsr() { rcs2log $* | $PAGER } cvss() { cvs status -v $* } debbug() { ${=BROWSER} "http://bugs.debian.org/$*" } - debbugm() { bts show --mbox $1 } # provide bugnummer as $1 + debbugm() { bts show --mbox $1 } # provide bugnummer as "$1" disassemble(){ gcc -pipe -S -o - -O -g $* | as -aldh -o /dev/null } dmoz() { ${=BROWSER} http://search.dmoz.org/cgi-bin/search\?search=${1// /_} } dwicti() { ${=BROWSER} http://de.wiktionary.org/wiki/${(C)1// /_} } @@ -275,6 +209,7 @@ fir() { firefox -a firefox -remote "openURL($1)" } ggogle() { ${=BROWSER} "http://groups.google.com/groups?q=$*" } google() { ${=BROWSER} "http://www.google.com/search?&num=100&q=$*" } + mcd() { mkdir -p "$@"; cd "$@" } # mkdir && cd mdiff() { diff -udrP "$1" "$2" > diff.`date "+%Y-%m-%d"`."$1" } memusage(){ ps aux | awk '{if (NR > 1) print $5; if (NR > 2) print "+"} END { print "p" }' | dc } mggogle() { ${=BROWSER} "http://groups.google.com/groups?selm=$*" } @@ -291,31 +226,24 @@ wikien() { ${=BROWSER} http://en.wikipedia.org/wiki/"$*" } wodeb () { ${=BROWSER} "http://packages.debian.org/cgi-bin/search_contents.pl?word=$1&version=${2:-unstable}" } - which google >/dev/null 2>&1 && gex () { google "\"[ $1]\" $*" } # exact search at google + which google &>/dev/null && gex () { google "\"[ $1]\" $*" } # exact search at google + + # download video from youtube + ytdl() { + if ! [ -n "$2" ] ; then + print "Usage: ydtl http://youtube.com/watch?v=.... outputfile.flv">&2 + return 1 + else + wget -O${2} "http://youtube.com/get_video?"${${${"$(wget -o/dev/null -O- "${1}" | grep -e watch_fullscreen)"}##*watch_fullscreen\?}%%\&fs=*} + fi + } + # Function Usage: doc packagename doc() { cd /usr/share/doc/$1 && ls } _doc() { _files -W /usr/share/doc -/ } compdef _doc doc -# debian upgrade - upgrade () { - if [ -z $1 ] ; then - $SUDO apt-get update - $SUDO apt-get -u upgrade - else - ssh $1 $SUDO apt-get update - # ask before the upgrade - local dummy - ssh $1 $SUDO apt-get --no-act upgrade - echo -n "Process the upgrade ?" - read -q dummy - if [[ $dummy == "y" ]] ; then - ssh $1 $SUDO apt-get -u upgrade --yes - fi - fi - } - # make screenshot of current desktop (use 'import' from ImageMagic) sshot() { [[ ! -d ~/shots ]] && mkdir ~/shots @@ -323,7 +251,6 @@ cd ~/shots ; sleep 5; import -window root shot_`date --iso-8601=m`.jpg } - # list images only limg() { local -a images @@ -335,7 +262,6 @@ fi } - # create pdf file from source code makereadable() { output=$1 @@ -351,6 +277,7 @@ pcre_compile $1 && \ pcre_match $2 && echo "regex matches" || echo "regex does not match" } + # list files which have been modified within the last x days new() { print -l *(m-$1) } @@ -389,45 +316,6 @@ cd ~$dir } -# provide 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) # 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}'<" - } - # find out which libs define a symbol # usage example: 'lcheck strcpy' lcheck() { @@ -523,14 +411,8 @@ print -z "${cmd[$answer]#*$TAB}" } -# mkdir && cd - mcd() { mkdir -p "$@"; cd "$@" } # mkdir && cd - -# cd && ls - cl() { cd $1 && ls -a } - # Use vim to convert plaintext to HTML - 2html() { vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null } + 2html() { vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 &>/dev/null } # Usage: simple-extract # Description: extracts archived files (maybe) @@ -595,6 +477,7 @@ fi } +# follow symlinks folsym() { if [[ -e $1 || -h $1 ]]; then file=$1 @@ -668,13 +551,26 @@ # a small check to see which DIR is located on which server/partition. # stolen and modified from Sven's zshrc.forall dirspace() { - for dir in $path; - do - (cd $dir; echo "-<$dir>"; du -shx .; echo); + 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 } -# $ show_print `cat /etc/passwd` +# % slow_print `cat /etc/passwd` slow_print() { for argument in "${@}" do @@ -687,6 +583,7 @@ print "" } +# display system state status() { print "" print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")"" @@ -698,6 +595,7 @@ print "" } +# Rip an audio CD audiorip() { mkdir -p ~/ripps cd ~/ripps @@ -715,6 +613,7 @@ fi } +# and burn it audioburn() { cd ~/ripps cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc @@ -730,6 +629,7 @@ fi } +# Make an audio CD from all mp3 files mkaudiocd() { cd ~/ripps for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done @@ -739,6 +639,7 @@ for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done } +# Create an ISO image. You are prompted for volume name, filename and directory mkiso() { echo " * Volume name " read volume @@ -749,7 +650,7 @@ mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files } -# generate thumbnails ;) +# simple thumbnails generator genthumbs () { rm -rf thumb-* index.html echo " @@ -900,7 +801,7 @@ } # highlight important stuff in diff output, usage example: hg diff | hidiff - [ -x =histring ] && \ + [ -x $(which histring) ] && \ alias hidiff="histring -fE '^Comparing files .*|^diff .*' | histring -c yellow -fE '^\-.*' | histring -c green -fE '^\+.*'" # rename pictures based on information found in exif headers @@ -919,10 +820,149 @@ fi fi } + +# open file in vim 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' + vim ${params} + } + +# get_ic() - queries imap servers for capabilities; real simple. no imaps + ic_get() { + local port + if [[ ! -z $1 ]]; then + port=${2:-143} + print "querying imap server on $1:${port}...\n"; + print "a1 capability\na2 logout\n" | nc $1 ${port} + else + print "usage:\n $0 [port]" + fi + } + +# creates a Maildir/ with its {new,cur,tmp} subdirs + mkmaildir() { + local root subdir + root=${MAILDIR_ROOT:-${HOME}/Mail} + if [[ -z ${1} ]] ; then print "Usage\n $0 " ; fi + subdir=${1} + mkdir -p ${root}/${subdir}/{cur,new,tmp} + } + +# xtrename() rename xterm from within GNU-screen + xtrename() { + if [[ -z ${DISPLAY} ]] ; then + printf 'xtrename only makes sense in X11.\n' + return 1 + fi + if [[ -z ${1} ]] ; then + printf 'usage: xtrename() "title for xterm"\n' + printf ' renames the title of xterm from _within_ screen.\n' + printf ' Also works without screen.\n' + return 0 + fi + print -n "\eP\e]0;${1}\C-G\e\\" + return 0 + } + +# hl() highlighted less +# http://ft.bewatermyfriend.org/comp/data/zsh/zfunct.html + if [[ -x $(which highlight) ]] ; then + function hl() { + local theme lang + theme=${HL_THEME:-""} + case ${1} in + (-l|--list) + ( printf 'available languages (syntax parameter):\n\n' ; + highlight --list-langs ; ) | less -SMr + ;; + (-t|--themes) + ( printf 'available themes (style parameter):\n\n' ; + highlight --list-themes ; ) | less -SMr + ;; + (-h|--help) + printf 'usage: hl \n' + printf ' available options: --list (-l), --themes (-t), --help (-h)\n\n' + printf ' Example: hl c main.c\n' + ;; + (*) + if [[ -z ${2} ]] || (( ${#argv} > 2 )) ; then + printf 'usage: hl \n' + printf ' available options: --list (-l), --themes (-t), --help (-h)\n' + (( ${#argv} > 2 )) && printf ' Too many arguments.\n' + return 1 + fi + lang=${1%:*} + [[ ${1} == *:* ]] && [[ -n ${1#*:} ]] && theme=${1#*:} + if [[ -n ${theme} ]] ; then + highlight --xterm256 --syntax ${lang} --style ${theme} ${2} | less -SMr + else + highlight --ansi --syntax ${lang} ${2} | less -SMr + fi + ;; + esac + return 0 + } + # ... and a proper completion for hl() + # needs 'highlight' as well, so it fits fine in here. + function _hl_genarg() { + local expl + if [[ -prefix 1 *: ]] ; then + local themes + themes=(${${${(f)"$(LC_ALL=C highlight --list-themes)"}/ #/}:#*(Installed|Use name)*}) + compset -P 1 '*:' + _wanted -C list themes expl theme compadd ${themes} + else + local langs + langs=(${${${(f)"$(LC_ALL=C highlight --list-langs)"}/ #/}:#*(Installed|Use name)*}) + _wanted -C list languages expl languages compadd -S ':' -q ${langs} + fi + } + function _hl_complete() { + _arguments -s '1: :_hl_genarg' '2:files:_path_files' + } + compdef _hl_complete hl + fi + +# create small urls via tinyurl.com using wget, grep and sed + zurl() { + [[ -z ${1} ]] && print "please give an url to shrink." && return 1 + local url=${1} + local tiny="http://tinyurl.com/create.php?url=" + #print "${tiny}${url}" ; return + wget -O- \ + -o/dev/null \ + "${tiny}${url}" \ + | grep -Eio 'value="(http://tinyurl.com/.*)"' \ + | sed 's/value=//;s/"//g' +} + +# change fluxbox keys from 'Alt-#' to 'Alt-F#' and vice versa + fluxkey-change() { + [ -n "$FLUXKEYS" ] || local FLUXKEYS="$HOME/.fluxbox/keys" + if ! [ -r "$FLUXKEYS" ] ; then + echo "Sorry, \$FLUXKEYS file $FLUXKEYS could not be read - nothing to be done." + return 1 + else + if grep -q 'Mod1 F[0-9] :Workspace [0-9]' $FLUXKEYS ; then + echo -n 'Switching to Alt-# mode in ~/.fluxbox/keys: ' + sed -i -e 's|^\(Mod[0-9]\+[: space :]\+\)F\([0-9]\+[: space :]\+:Workspace.*\)|\1\2|' $FLUXKEYS && echo done || echo failed + elif grep -q 'Mod1 [0-9] :Workspace [0-9]' $FLUXKEYS ; then + echo -n 'Switching to Alt-F# mode in ~/.fluxbox/keys: ' + sed -i -e 's|^\(Mod[0-9]\+[: space :]\+\)\([0-9]\+[: space :]\+:Workspace.*\)|\1F\2|' $FLUXKEYS && echo done || echo failed + else + echo 'Sorry, do not know what to do.' + return 1 + fi + fi + } + # }}} # mercurial related stuff {{{ - if type -p hg >/dev/null 2>&1 ; then + if type -p hg &>/dev/null ; then # gnu like diff for mercurial # http://www.selenic.com/mercurial/wiki/index.cgi/TipsAndTricks hgdi() { @@ -932,6 +972,9 @@ # build debian package 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 @@ -964,7 +1007,7 @@ # export PYTHONPATH=${HOME}/lib/python fi } - + fi # end of check whether we have the 'hg'-executable # get current mercurial snapshot