Add zsh-lookup sub-system
[grml-etc-core.git] / usr_share_grml / zsh / functions / Lookup / LOOKUP_help
1 ### vim:ft=zsh:foldmethod=marker
2 ## Copyright: 2009, Frank Terbeck <ft@bewatermyfriend.org>
3
4 LOOKUP_guard || return 1
5
6 if [[ $1 != '-f' ]] ; then
7     (( lookup_help == 0 )) && return 1
8 else
9     shift
10 fi
11
12 local line use_pager pager_auto pager
13 local -i prompt_height
14 local -a lines
15
16 zstyle -t "${lookup_context}" use-pager  && use_pager='yes'  || use_pager='no'
17 zstyle -t "${lookup_context}" pager-auto && pager_auto='yes' || pager_auto='no'
18 zstyle -s "${lookup_context}" pager pager || pager=${PAGER:-more}
19 zstyle -s "${lookup_context}" prompt-height prompt_height || prompt_height=1
20 (( prompt_height == 0 )) && prompt_height=1
21
22 if [[ ${LINES} != [0-9]## ]] || [[ ${LINES} -eq 0 ]] ; then
23     # $LINES is either 0, empty or other rubbish that's not a positive integer.
24     pager_auto='no'
25 fi
26
27 if [[ ${use_pager} == 'no' ]] ; then
28     LOOKUP_help_${backend}
29     return 0
30 fi
31
32 if [[ ${use_pager} == 'yes' ]] && [[ ${pager_auto} == 'no' ]] ; then
33     LOOKUP_help_${backend} | ${=pager}
34     return 0
35 fi
36
37 # use-pager: true, pager-auto: true
38 lines=()
39 LOOKUP_help_${backend} | while IFS='' read -r line; do
40     lines+=( "${line}" )
41 done
42
43 if (( ${#lines} > LINES - prompt_height )); then
44     print -l -- "${lines[@]}" | ${=pager}
45 else
46     print -l -- "${lines[@]}"
47 fi
48 return 0