From e1491794ce35da3eb1b7a3731f1e1b9a5e93a9a0 Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Mon, 28 Nov 2011 22:10:27 +0100 Subject: [PATCH] zshrc: Move hl and its completion to their own files Signed-off-by: Frank Terbeck --- etc/zsh/zshrc | 60 ------------------------- usr_share_grml/zsh/completion/unix/_hl_complete | 17 +++++++ usr_share_grml/zsh/functions/hl | 36 +++++++++++++++ 3 files changed, 53 insertions(+), 60 deletions(-) create mode 100644 usr_share_grml/zsh/completion/unix/_hl_complete create mode 100644 usr_share_grml/zsh/functions/hl diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 8726dbc..2169cc1 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -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 \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 diff --git a/usr_share_grml/zsh/completion/unix/_hl_complete b/usr_share_grml/zsh/completion/unix/_hl_complete new file mode 100644 index 0000000..28363d4 --- /dev/null +++ b/usr_share_grml/zsh/completion/unix/_hl_complete @@ -0,0 +1,17 @@ +#compdef hl + +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 +} + +_arguments -s '1: :_hl_genarg' '2:files:_path_files' diff --git a/usr_share_grml/zsh/functions/hl b/usr_share_grml/zsh/functions/hl new file mode 100644 index 0000000..258ea7e --- /dev/null +++ b/usr_share_grml/zsh/functions/hl @@ -0,0 +1,36 @@ +# hl() highlighted less +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 -- 2.1.4