X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=96509d4e51c8d3d3c907ff29afd7d0605dee3289;hb=af1880477d99f931a695a9ea316d9ebf1ea53129;hp=b87dab9fa8493034dfd642f3c0384f499940eb10;hpb=433f1c4bbbfb6c9b9aff0f26d42be4f2e6e07886;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index b87dab9..96509d4 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -2896,61 +2896,6 @@ lcheck() { 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)$(}/${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 @@ -2977,42 +2922,6 @@ trans() { 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 # Using option -d deletes the original archive file. #f5# Smart archive extractor @@ -3207,50 +3116,6 @@ show-archive() { fi } -# It's shameless stolen from -#f5# Use \kbd{vim} as your manpage reader -vman() { - emulate -L zsh - if (( ${#argv} == 0 )); then - printf 'usage: vman \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() { @@ -3261,132 +3126,6 @@ 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 -} - -# Rip an audio CD -#f5# Rip an audio CD -audiorip() { - mkdir -p ~/ripps - cd ~/ripps - cdrdao read-cd --device $DEVICE --driver generic-mmc audiocd.toc - cdrdao read-cddb --device $DEVICE --driver generic-mmc audiocd.toc - echo " * Would you like to burn the cd now? (yes/no)" - read input - if [[ "$input" = "yes" ]] ; then - echo " ! Burning Audio CD" - audioburn - echo " * done." - else - echo " ! Invalid response." - fi -} - -# and burn it -#f5# Burn an audio CD (in combination with audiorip) -audioburn() { - cd ~/ripps - cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc - echo " * Should I remove the temporary files? (yes/no)" - read input - if [[ "$input" = "yes" ]] ; then - echo " ! Removing Temporary Files." - cd ~ - rm -rf ~/ripps - echo " * done." - else - echo " ! Invalid response." - fi -} - -#f5# Make an audio CD from all mp3 files -mkaudiocd() { - # TODO: do the renaming more zshish, possibly with zmv() - emulate -L zsh - cd ~/ripps - for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done - for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done - for i in *.mp3; do mpg123 -w `basename $i .mp3`.wav $i; done - normalize -m *.wav - for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done -} - -#f5# Create an ISO image. You are prompted for\\&\quad volume name, filename and directory -mkiso() { - emulate -L zsh - echo " * Volume name " - read volume - echo " * ISO Name (ie. tmp.iso)" - read iso - echo " * Directory or File" - read files - mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files -} - -#f5# Simple thumbnails generator -genthumbs() { - rm -rf thumb-* index.html - echo " - - - Images - - " > index.html - for f in *.(gif|jpeg|jpg|png) ; do - convert -size 100x200 "$f" -resize 100x200 thumb-"$f" - echo " " >> index.html - done - echo " - -" >> index.html -} - #f5# Set all ulimit parameters to \kbd{unlimited} allulimit() { ulimit -c unlimited @@ -3398,74 +3137,11 @@ allulimit() { ulimit -t unlimited } -#f5# RFC 2396 URL encoding in Z-Shell -urlencode() { - emulate -L zsh - setopt extendedglob - input=( ${(s::)1} ) - print ${(j::)input/(#b)([^A-Za-z0-9_.!~*\'\(\)-])/%${(l:2::0:)$(([##16]#match))}} -} - -# http://strcat.de/blog/index.php?/archives/335-Software-sauber-deinstallieren...html -#f5# Log 'make install' output -mmake() { - emulate -L zsh - [[ ! -d ~/.errorlogs ]] && mkdir ~/.errorlogs - make -n install > ~/.errorlogs/${PWD##*/}-makelog -} - -#f5# Indent source code -smart-indent() { - indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs "$@" -} - # highlight important stuff in diff output, usage example: hg diff | hidiff #m# a2 hidiff \kbd{histring} oneliner for diffs check_com -c 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 -#f5# Rename pictures based on information found in exif headers -exirename() { - emulate -L zsh - if [[ $# -lt 1 ]] ; then - echo 'Usage: jpgrename $FILES' >& 2 - return 1 - else - echo -n 'Checking for jhead with version newer than 1.9: ' - jhead_version=`jhead -h | grep 'used by most Digital Cameras. v.*' | awk '{print $6}' | tr -d v` - if [[ $jhead_version > '1.9' ]]; then - echo 'success - now running jhead.' - jhead -n%Y-%m-%d_%Hh%M_%f $* - else - echo 'failed - exiting.' - fi - fi -} - -# get_ic() - queries imap servers for capabilities; real simple. no imaps -ic_get() { - emulate -L zsh - 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() { - emulate -L zsh - local root subdir - root=${MAILDIR_ROOT:-${HOME}/Mail} - if [[ -z ${1} ]] ; then print "Usage:\n $0 " ; return 1 ; fi - subdir=${1} - mkdir -p ${root}/${subdir}/{cur,new,tmp} -} - #f5# Change the xterm title from within GNU-screen xtrename() { emulate -L zsh @@ -3488,66 +3164,6 @@ xtrename() { return 0 } -# hl() highlighted less -# http://ft.bewatermyfriend.org/comp/data/zsh/zfunct.html -if check_com -c highlight ; then - function hl() { - emulate -L zsh - 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 -O xterm256 --syntax ${lang} --style ${theme} ${2} | less -SMr - else - highlight -O 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 - # TODO: # Rewrite this by either using tinyurl.com's API # or using another shortening service to comply with @@ -3589,29 +3205,6 @@ fi # fi #} -#f2# Print a specific line of file(s). -linenr () { - emulate -L zsh - 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() { emulate -L zsh @@ -3660,72 +3253,6 @@ whatwhen() { esac } -# change fluxbox keys from 'Alt-#' to 'Alt-F#' and vice versa -fluxkey-change() { - emulate -L zsh - [[ -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 -} - -# retrieve weather information on the console -# Usage example: 'weather LOWG' -weather() { - emulate -L zsh - [[ -n "$1" ]] || { - print 'Usage: weather ' >&2 - print 'List of stations: http://en.wikipedia.org/wiki/List_of_airports_by_ICAO_code'>&2 - return 1 - } - - local VERBOSE="yes" # TODO: Make this a command line switch - - local ODIR=`pwd` - local PLACE="${1:u}" - local DIR="${HOME}/.weather" - local LOG="${DIR}/log" - - [[ -d ${DIR} ]] || { - print -n "Creating ${DIR}: " - mkdir ${DIR} - print 'done' - } - - print "Retrieving information for ${PLACE}:" - print - cd ${DIR} && wget -T 10 --no-verbose --output-file=$LOG --timestamping http://weather.noaa.gov/pub/data/observations/metar/decoded/$PLACE.TXT - - if [[ $? -eq 0 ]] ; then - if [[ -n "$VERBOSE" ]] ; then - cat ${PLACE}.TXT - else - DATE=$(grep 'UTC' ${PLACE}.TXT | sed 's#.* /##') - TEMPERATURE=$(awk '/Temperature/ { print $4" degree Celcius / " $2" degree Fahrenheit" }' ${PLACE}.TXT | tr -d '(') - echo "date: $DATE" - echo "temp: $TEMPERATURE" - fi - else - print "There was an error retrieving the weather information for $PLACE" >&2 - cat $LOG - cd $ODIR - return 1 - fi - cd $ODIR -} - # mercurial related stuff if check_com -c hg ; then # gnu like diff for mercurial