2020-11-13 02:32:17 +08:00
|
|
|
# Requires colors autoload.
|
|
|
|
# See termcap(5).
|
|
|
|
|
|
|
|
# Set up once, and then reuse. This way it supports user overrides after the
|
|
|
|
# plugin is loaded.
|
|
|
|
typeset -AHg less_termcap
|
|
|
|
|
|
|
|
# bold & blinking mode
|
|
|
|
less_termcap[mb]="${fg_bold[red]}"
|
|
|
|
less_termcap[md]="${fg_bold[red]}"
|
|
|
|
less_termcap[me]="${reset_color}"
|
|
|
|
# standout mode
|
|
|
|
less_termcap[so]="${fg_bold[yellow]}${bg[blue]}"
|
|
|
|
less_termcap[se]="${reset_color}"
|
|
|
|
# underlining
|
|
|
|
less_termcap[us]="${fg_bold[green]}"
|
|
|
|
less_termcap[ue]="${reset_color}"
|
|
|
|
|
|
|
|
# Absolute path to this file's directory.
|
|
|
|
typeset __colored_man_pages_dir="${0:A:h}"
|
2014-07-11 21:11:49 +08:00
|
|
|
|
2018-09-29 22:01:41 +08:00
|
|
|
function colored() {
|
2020-11-13 02:32:17 +08:00
|
|
|
local -a environment
|
|
|
|
|
|
|
|
# Convert associative array to plain array of NAME=VALUE items.
|
|
|
|
local k v
|
|
|
|
for k v in "${(@kv)less_termcap}"; do
|
|
|
|
environment+=( "LESS_TERMCAP_${k}=${v}" )
|
|
|
|
done
|
|
|
|
|
|
|
|
# Prefer `less` whenever available, since we specifically configured
|
|
|
|
# environment for it.
|
|
|
|
environment+=( PAGER="${commands[less]:-$PAGER}" )
|
|
|
|
|
|
|
|
# See ./nroff script.
|
|
|
|
if [[ "$OSTYPE" = solaris* ]]; then
|
|
|
|
environment+=( PATH="${__colored_man_pages_dir}:$PATH" )
|
|
|
|
fi
|
|
|
|
|
|
|
|
command env $environment "$@"
|
2018-09-29 22:01:41 +08:00
|
|
|
}
|
|
|
|
|
2020-03-31 02:13:12 +08:00
|
|
|
# Colorize man and dman/debman (from debian-goodies)
|
|
|
|
function man \
|
2020-11-13 02:32:17 +08:00
|
|
|
dman \
|
|
|
|
debman {
|
|
|
|
colored $0 "$@"
|
2013-03-30 23:00:40 +08:00
|
|
|
}
|