colored-man-pages.plugin.zsh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Requires colors autoload.
  2. # See termcap(5).
  3. # Set up once, and then reuse. This way it supports user overrides after the
  4. # plugin is loaded.
  5. typeset -AHg less_termcap
  6. # bold & blinking mode
  7. less_termcap[mb]="${fg_bold[red]}"
  8. less_termcap[md]="${fg_bold[red]}"
  9. less_termcap[me]="${reset_color}"
  10. # standout mode
  11. less_termcap[so]="${fg_bold[yellow]}${bg[blue]}"
  12. less_termcap[se]="${reset_color}"
  13. # underlining
  14. less_termcap[us]="${fg_bold[green]}"
  15. less_termcap[ue]="${reset_color}"
  16. # Absolute path to this file's directory.
  17. typeset __colored_man_pages_dir="${0:A:h}"
  18. function colored() {
  19. local -a environment
  20. # Convert associative array to plain array of NAME=VALUE items.
  21. local k v
  22. for k v in "${(@kv)less_termcap}"; do
  23. environment+=( "LESS_TERMCAP_${k}=${v}" )
  24. done
  25. # Prefer `less` whenever available, since we specifically configured
  26. # environment for it.
  27. environment+=( PAGER="${commands[less]:-$PAGER}" )
  28. # See ./nroff script.
  29. if [[ "$OSTYPE" = solaris* ]]; then
  30. environment+=( PATH="${__colored_man_pages_dir}:$PATH" )
  31. fi
  32. command env $environment "$@"
  33. }
  34. # Colorize man and dman/debman (from debian-goodies)
  35. function man \
  36. dman \
  37. debman {
  38. colored $0 "$@"
  39. }