home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Shells / zsh-3.0.5-MIHS / src / Functions / run-help < prev    next >
Encoding:
Paul Falstad's zsh script  |  1996-08-23  |  1.6 KB  |  74 lines

  1. #!/usr/local/bin/zsh
  2. #
  3. # Figure out where to get the best help, and get it.
  4. #
  5. # Install this function by placing it in your FPATH and then
  6. # adding to your .zshrc the lines:
  7. #    unalias run-help
  8. #    autoload run-help
  9. #
  10. # Bart Schaefer <schaefer@brasslantern.com>
  11. #
  12. emulate -R zsh                # Requires zsh 3.0-pre5 or later
  13. setopt localoptions
  14.  
  15. # Check whether Util/helpfiles has been used to generate zsh help
  16. if [[ $1 == "-l" ]]
  17. then
  18.     if [[ -n "${HELPDIR:-}" ]]
  19.     then
  20.     echo 'Here is a list of topics for which help is available:'
  21.     echo ""
  22.     print -rc $HELPDIR/*(:t)
  23.     else
  24.     echo 'There is no list of help topics available at this time'
  25.     fi
  26.     return 0
  27. elif [[ -n "${HELPDIR:-}" && -r $HELPDIR/$1 && $1 != compctl ]]
  28. then
  29.     ${=PAGER:-more} $HELPDIR/$1
  30.     return $?
  31. fi
  32.  
  33. # No zsh help, use "whence" to figure out where else we might look
  34. local what places newline='
  35. '
  36. integer i=0 didman=0
  37.  
  38. places=( "${(@f)$(builtin whence -va $1)}" )
  39.  
  40. while ((i++ < $#places))
  41. do
  42.     what=$places[$i]
  43.     builtin print -r $what
  44.     case $what in
  45.     (*( is an alias)*)
  46.     [[ ${what[(w)6]:t} != ${what[(w)1]} ]] && run-help ${what[(w)6]:t}
  47.     ;;
  48.     (*( is a * function))
  49.     builtin functions ${what[(w)1]} | ${=PAGER:-more}
  50.     ;;
  51.     (*( is a * builtin))
  52.     case ${what[(w)1]} in
  53.     (compctl) man zshcompctl;;
  54.     (bindkey) man zshzle;;
  55.     (*setopt) man zshoptions;;
  56.     (*) man zshbuiltins;;
  57.     esac
  58.     ;;
  59.     (*( is hashed to *))
  60.     man ${what[(w)-1]:t}
  61.     ;;
  62.     (*)
  63.     ((! didman++)) && man $1
  64.     ;;
  65.     esac
  66.     if ((i < $#places && ! didman))
  67.     then
  68.     builtin print -nP "%SPress any key for more help or q to quit%s"
  69.     builtin read -k what
  70.     [[ $what != $newline ]] && echo
  71.     [[ $what == [qQ] ]] && break
  72.     fi
  73. done
  74.