X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Fskel%2F.zshrc;h=d7b2840e6baef3342e57ff8e68804c5ec8ea35e3;hb=36b19d3d797d334b963eb77e608250e930742e76;hp=7af2f0a91311ca4200b3aaf81363442f99b48086;hpb=d3f2ae885505d525fec84b17e7cdbadd4b8d712d;p=grml-etc-core.git diff --git a/etc/skel/.zshrc b/etc/skel/.zshrc index 7af2f0a..d7b2840 100644 --- a/etc/skel/.zshrc +++ b/etc/skel/.zshrc @@ -3,19 +3,29 @@ # 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: Mit Aug 08 21:22:03 CEST 2007 [mika] ################################################################################ # source ~/.zshrc.global {{{ + # see /etc/zsh/zshrc for some general settings # If you don't have write permissions to /etc/zsh/zshrc on your own # copy the file to your $HOME as /.zshrc.global and we source it: -xsource "${HOME}/.zshrc.global" + +# Note, that xsource() is defined in the global file, so here, +# we will have to do the sourcing manually for once: + +[[ -z "$ZSHRC_GLOBAL_HAS_BEEN_READ" ]] \ +&& [[ -r "${HOME}/.zshrc.global" ]] \ +&& source "${HOME}/.zshrc.global" # }}} # check whether global file has been read {{{ if [[ -z "$ZSHRC_GLOBAL_HAS_BEEN_READ" ]] ; then - print 'Warning: global zsh config has not been read'>&2 + print 'Warning: global zsh config has not been read.' >&2 + print ' prepare for possible errors!' >&2 + print '' >&2 + print 'See our refcard for info on how to get the complete configuration:' >&2 + print ' ' >&2 fi # }}} @@ -27,6 +37,7 @@ fi # completion system {{{ # just make sure it is loaded in this file too +# TODO: is this *really* needed? compsys should be run in the global zshrc already. check_com compinit || { autoload -U compinit && compinit } # }}} @@ -34,7 +45,7 @@ check_com compinit || { autoload -U compinit && compinit } check_com isgrmlsmall || function isgrmlsmall () { return 1 } # }}} -## variables {{{ +# variables {{{ # do you want grmlsmall-specific adjustments? GRMLSMALL_SPECIFIC=1 @@ -52,8 +63,6 @@ if [[ -z "$BROWSER" ]] ; then check_com -c w3m && export BROWSER=w3m fi fi -#v# -(( ${+PAGER} )) || export PAGER="less" #m# v QTDIR \kbd{/usr/share/qt[34]}\quad [for non-root only] [[ -d /usr/share/qt3 ]] && export QTDIR=/usr/share/qt3 @@ -64,7 +73,7 @@ fi [[ -f /usr/share/classpath/glibj.zip ]] && export JIKESPATH=/usr/share/classpath/glibj.zip # }}} -## set options {{{ +# set options {{{ # Allow comments even in interactive shells i. e. # $ uname # This command prints system informations @@ -104,7 +113,7 @@ fi # alias -g V='| vim -' # }}} -## aliases {{{ +# aliases {{{ # Xterm resizing-fu. # Based on http://svn.kitenet.net/trunk/home-full/.zshrc?rev=11710&view=log (by Joey Hess) @@ -210,6 +219,9 @@ alias fblinks='links2 -driver fb' alias insecssh='ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"' alias insecscp='scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"' +# simple webserver +check_com -c python && alias http="python -m SimpleHTTPServer" + # Use 'g' instead of 'git': check_com g || alias g='git' @@ -243,14 +255,32 @@ if check_com isutfenv && check_com luit ; then fi # }}} -## useful functions {{{ +# useful functions {{{ # searching #f4# Search for newspostings from authors agoogle() { ${=BROWSER} "http://groups.google.com/groups?as_uauthors=$*" ; } -#f4# Search Debian Bug Tracking System by BugID in mbox format -debbug() { ${=BROWSER} "http://bugs.debian.org/$*" } #f4# Search Debian Bug Tracking System +debbug() { + setopt localoptions extendedglob + if [[ $# -eq 1 ]]; then + case "$1" in + ([0-9]##) + ${=BROWSER} "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=$1" + ;; + (*@*) + ${=BROWSER} "http://bugs.debian.org/cgi-bin/pkgreport.cgi?submitter=$1" + ;; + (*) + ${=BROWSER} "http://bugs.debian.org/$*" + ;; + esac + else + print "$0 needs one argument" + return 1 + fi +} +#f4# Search Debian Bug Tracking System in mbox format debbugm() { bts show --mbox $1 } # provide bugnummer as "$1" #f4# Search DMOZ dmoz() { ${=BROWSER} http://search.dmoz.org/cgi-bin/search\?search=${1// /_} } @@ -332,6 +362,19 @@ ytdl() { fi } +# Function Usage: uopen $URL/$file +#f5# Download a file and display it locally +uopen() { + 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} @@ -571,6 +614,7 @@ show-archive() { *.tgz) tar -ztf $1 ;; *.zip) unzip -l $1 ;; *.bz2) bzless $1 ;; + *.deb) dpkg-deb --fsys-tarfile $1 | tar -tf - -- ;; *) echo "'$1' Error. Please go away" ;; esac else @@ -578,39 +622,6 @@ show-archive() { fi } -# TODO: isn't ssl() like this, but clean? -# I'd like to remove this, it's a gross hack, IMHO -ft -#f5# Follow symlinks -folsym() { - if [[ -e $1 || -h $1 ]] ; then - file=$1 - else - file=`which $1` - fi - if [[ -e $file || -L $file ]] ; then - if [[ -L $file ]] ; then - echo `ls -ld $file | perl -ane 'print $F[7]'` '->' - folsym `perl -le '$file = $ARGV[0]; - $dest = readlink $file; - if ($dest !~ m{^/}) { - $file =~ s{(/?)[^/]*$}{$1$dest}; - } else { - $file = $dest; - } - $file =~ s{/{2,}}{/}g; - while ($file =~ s{[^/]+/\.\./}{}) { - ; - } - $file =~ s{^(/\.\.)+}{}; - print $file' $file` - else - ls -d $file - fi - else - echo $file - fi -} - # It's shameless stolen from #f5# Use \kbd{vim} as your manpage reader vman() { man $* | col -b | view -c 'set ft=man nomod nolist' - } @@ -627,6 +638,22 @@ readme() { 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 +} + # suidfind() { ls -latg $path | grep '^...s' } #f5# Find all files in \$PATH with setuid bit set suidfind() { ls -latg $path/*(sN) } @@ -792,7 +819,7 @@ ogg2mp3_192() { urlencode() { setopt localoptions extendedglob input=( ${(s::)1} ) - print ${(j::)input/(#b)([^A-Za-z0-9_.!~*\'\(\)-])/%$(([##16]#match))} + print ${(j::)input/(#b)([^A-Za-z0-9_.!~*\'\(\)-])/%${(l:2::0:)$(([##16]#match))}} } #f5# Install x-lite (VoIP software) @@ -837,11 +864,11 @@ getskypebeta() { getgizmo() { setopt local_options setopt errreturn - echo "gconf2-common and libgconf2-4 have to be available. Installing therefor." + echo "libgtk2.0-0, gconf2, libstdc++6, libasound2 and zlib1g have to be available. Installing." $SUDO apt-get update - $SUDO apt-get install gconf2-common libgconf2-4 - wget $(lynx --dump http://www.gizmoproject.com/download-linux.html | awk '/\.deb/ {print $2" "}' | tr -d '\n') - $SUDO dpkg -i libsipphoneapi*.deb bonjour_*.deb gizmo-*.deb && echo "gizmo installed." + $SUDO apt-get install libgtk2.0-0 gconf2 libstdc++6 libasound2 zlib1g + wget "$(lynx --dump http://gizmo5.com/pc/download/linux/ | awk '/libstdc\+\+6.*\.deb/ {print $2}')" + $SUDO dpkg -i gizmo-project*.deb && echo "gizmo installed." } #f5# Get and run AIR (Automated Image and Restore) @@ -882,17 +909,22 @@ git-get-commit() { } #f5# Get specific git diff -git-get-plaindiff() { +git-get-plaindiff () { if [[ -z $GITTREE ]] ; then - GITTREE='linux/kernel/git/torvalds/linux-2.6.git' + GITTREE='linux/kernel/git/torvalds/linux-2.6.git' fi - if ! [[ -z $1 ]] ; then - wget "http://kernel.org/git/?p=$GITTREE;a=commitdiff_plain;h=$1" -O $1.diff + if [[ -z $1 ]] ; then + echo 'Usage: git-get-plaindiff ' else - echo 'Usage: git-get-plaindiff ' + echo -n "Downloading $1.diff ... " + # avoid "generating ..." stuff from kernel.org server: + wget --quiet "http://kernel.org/git/?p=$GITTREE;a=commitdiff_plain;h=$1" -O /dev/null + wget --quiet "http://kernel.org/git/?p=$GITTREE;a=commitdiff_plain;h=$1" -O $1.diff \ + && echo done || echo failed fi } + # http://strcat.de/blog/index.php?/archives/335-Software-sauber-deinstallieren...html #f5# Log 'make install' output mmake() { @@ -1046,6 +1078,79 @@ zurl() { | sed 's/value=//;s/"//g' } +#f2# Print a specific line of file(s). +linenr () { +# {{{ + if [ $# -lt 2 ] ; then + print "Usage: linenr [,] " ; return 1 + elif [ $# -eq 2 ] ; then + local number=$1 + local file=$2 + command ed -s $file <<< "${number}n" + else + local number=$1 + shift + for file in "$@" ; do + if [ ! -d $file ] ; then + echo "${file}:" + command ed -s $file <<< "${number}n" 2> /dev/null + else + continue + fi + done | less + fi +# }}} +} + +#f2# Find history events by search pattern and list them by date. +whatwhen() { +# {{{ + local usage help ident format_l format_s first_char remain first last + usage='USAGE: whatwhen [options] ' + 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 ` ' 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 '-' 'offset to the current history number; (default: -100)' + printf $format_s '<[-]first> []' '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 +# }}} +} + # change fluxbox keys from 'Alt-#' to 'Alt-F#' and vice versa fluxkey-change() { [[ -n "$FLUXKEYS" ]] || local FLUXKEYS="$HOME/.fluxbox/keys" @@ -1071,6 +1176,7 @@ fluxkey-change() { weather() { [[ -n "$1" ]] || { print 'Usage: weather ' >&2 + print 'List of stations: http://en.wikipedia.org/wiki/List_of_airports_by_ICAO_code'>&2 return 1 } @@ -1103,8 +1209,6 @@ weather() { return 1 fi } - - # }}} # mercurial related stuff {{{ @@ -1243,14 +1347,7 @@ gethgsnap() { # this allows us to stay in sync with /etc/skel/.zshrc # through 'ln -s /etc/skel/.zshrc ~/.zshrc' and put own # modifications in ~/.zshrc.local -if type xsource &>/dev/null ; then - xsource "${HOME}/.zshrc.local" -else - xsource "${HOME}/.zshrc.local" -fi - -# ...and remove utility functions again. -xunfunction +xsource "${HOME}/.zshrc.local" # }}}