4 # https://dev.0x50.de/projects/ftzsh/repository/revisions/master/entry/functions/hl
6 if ! [[ -x ${commands[highlight]} ]]; then
7 printf 'hl: Could not find `highlight'\'' binary!\n'
11 local context file format lang suffix syntax theme o
13 local -a pager hl_opts
14 local -A opt syntaxmap
16 while [[ $1 == -* ]]; do
28 printf 'usage: hl [OPTION(s)] <file(s)>\n'
32 ( printf 'available languages (syntax parameter):\n\n' ;
33 highlight --list-langs ; ) | less -SM
47 ( printf 'available themes (style parameter):\n\n' ;
48 highlight --list-themes ; ) | less -SM
57 printf 'hl: Unknown option `%s'\''!\n' $1
58 printf 'usage: hl [OPTION(s)] <file(s)>\n'
64 if (( ${#argv} < 1 )) ; then
65 printf 'usage: hl [OPTION(s)] <file(s)>\n'
66 printf ' available options: --list (-l), --themes (-t), --help (-h)\n'
67 printf ' --no-pager (--cat, -c), --syntax (-s)\n'
68 (( ${#argv} > 2 )) && printf ' Too many arguments.\n'
78 context=":functions:hl:$OSTYPE:$TERM:$suffix"
82 if (( ${+opt[format]} )); then
85 if ! zstyle -a $context format format; then
87 ((screen|xterm)-256color)
97 if (( ${+opt[theme]} )); then
100 zstyle -s $context theme theme || theme=solarized-dark
103 if (( nopager )); then
105 elif (( ${+opt[pager]} )); then
106 pager=${(z)opt[pager]}
108 zstyle -a $context pager pager || pager=( less -Mr )
111 if (( ${+opt[syntax]} )); then
112 syntax=${opt[syntax]}
114 if ! zstyle -s $context syntax syntax; then
115 (( ${+syntaxmap[$suffix]} )) && syntax=${syntaxmap[$suffix]}
118 [[ -n $syntax ]] && hl_opts=( --syntax=$syntax )
120 highlight --out-format=$format "${hl_opts[@]}" --style=$theme $file \