]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / colored-man-pages / colored-man-pages.plugin.zsh
1 # Requires colors autoload.
2 # See termcap(5).
3
4 # Set up once, and then reuse. This way it supports user overrides after the
5 # plugin is loaded.
6 typeset -AHg less_termcap
7
8 # bold & blinking mode
9 less_termcap[mb]="${fg_bold[red]}"
10 less_termcap[md]="${fg_bold[red]}"
11 less_termcap[me]="${reset_color}"
12 # standout mode
13 less_termcap[so]="${fg_bold[yellow]}${bg[blue]}"
14 less_termcap[se]="${reset_color}"
15 # underlining
16 less_termcap[us]="${fg_bold[green]}"
17 less_termcap[ue]="${reset_color}"
18
19 # Handle $0 according to the standard:
20 # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
21 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
22 0="${${(M)0:#/*}:-$PWD/$0}"
23
24 # Absolute path to this file's directory.
25 typeset -g __colored_man_pages_dir="${0:A:h}"
26
27 function colored() {
28   local -a environment
29
30   # Convert associative array to plain array of NAME=VALUE items.
31   local k v
32   for k v in "${(@kv)less_termcap}"; do
33     environment+=( "LESS_TERMCAP_${k}=${v}" )
34   done
35
36   # Prefer `less` whenever available, since we specifically configured
37   # environment for it.
38   environment+=( PAGER="${commands[less]:-$PAGER}" )
39
40   # See ./nroff script.
41   if [[ "$OSTYPE" = solaris* ]]; then
42     environment+=( PATH="${__colored_man_pages_dir}:$PATH" )
43   fi
44
45   command env $environment "$@"
46 }
47
48 # Colorize man and dman/debman (from debian-goodies)
49 function man \
50   dman \
51   debman {
52   colored $0 "$@"
53 }