colored-man-pages.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. # Handle $0 according to the standard:
  17. # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
  18. 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
  19. 0="${${(M)0:#/*}:-$PWD/$0}"
  20. # Absolute path to this file's directory.
  21. typeset -g __colored_man_pages_dir="${0:A:h}"
  22. function colored() {
  23. local -a environment
  24. # Convert associative array to plain array of NAME=VALUE items.
  25. local k v
  26. for k v in "${(@kv)less_termcap}"; do
  27. environment+=( "LESS_TERMCAP_${k}=${v}" )
  28. done
  29. # Prefer `less` whenever available, since we specifically configured
  30. # environment for it.
  31. environment+=( PAGER="${commands[less]:-$PAGER}" )
  32. # See ./nroff script.
  33. if [[ "$OSTYPE" = solaris* ]]; then
  34. environment+=( PATH="${__colored_man_pages_dir}:$PATH" )
  35. fi
  36. command env $environment "$@"
  37. }
  38. # Colorize man and dman/debman (from debian-goodies)
  39. function man \
  40. dman \
  41. debman {
  42. colored $0 "$@"
  43. }