[Home] Zsh logo

match-man

Zsh Wizard

Download match-man Return to Examples
  1. #!/usr/local/bin/zsh
  2. # match-man
  3. # Manual page matching.
  4. # assumes options NULLGLOB and EXTENDEDGLOB are set.
  5. # variables used in this shell. bigdirs and lildirs are in a subshell.
  6. local section arg line
  7. # read command line.
  8. read -Ac line
  9. # guess manual section. This could be fooled by other options, but
  10. # ought to be fairly robust.
  11. for arg in $line
  12. do
  13. if [[ "$arg" = ([1-9nlo]|[1-9](|[a-z])) ]]
  14. then
  15. section=$arg
  16. break
  17. fi
  18. done
  19. # form reply list from elements in $MANPATH.
  20. reply=($(
  21. # check if manpath is already set.
  22. if [[ -z "$MANPATH" ]]
  23. then
  24. # set manpath - in path:path:path form, and use it in (path path path) form.
  25. MANPATH=$(manpath)
  26. fi
  27. for bigdirs in $manpath
  28. do
  29. if [[ -z "$section" ]]
  30. then
  31. # no section specified, look in them all.
  32. for lildirs in $bigdirs/(man|cat)?(/N)
  33. do
  34. echo $lildirs/$1*$2.([1-9nlo]|[1-9](|[a-z]))(N:r:t) \
  35. $lildirs/$1*$2.([1-9nlo]|[1-9](|[a-z])).(gz|z|Z)(N:r:r:t)
  36. done
  37. else
  38. # section given, only search that one.
  39. echo $bigdirs/(man|cat)$section[1]/$1*$2.$section(|[a-z])(N:r:t) \
  40. $bigdirs/(man|cat)$section[1]/$1*$2.$section(|[a-z]).(gz|z|Z)(N:r:r:t)
  41. fi
  42. done
  43. ))