zshrc: Move hl and its completion to their own files
[grml-etc-core.git] / etc / zsh / zshrc
index b87dab9..2169cc1 100644 (file)
@@ -3488,66 +3488,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 <syntax[:theme]> <file>\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 <syntax[:theme]> <file>\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 +3529,6 @@ fi
 #    fi
 #}
 
-#f2# Print a specific line of file(s).
-linenr () {
-    emulate -L zsh
-    if [ $# -lt 2 ] ; then
-       print "Usage: linenr <number>[,<number>] <file>" ; 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 +3577,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 <station_id>' >&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