summaryrefslogtreecommitdiff
path: root/plugins/colored-man-pages/colored-man-pages.plugin.zsh
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2020-11-21 14:57:26 -0700
committerTuowen Zhao <ztuowen@gmail.com>2020-11-21 14:57:26 -0700
commit3aaa0bc62ece494dd2b6e47a191de79e562156f9 (patch)
tree53b623b60358bd9b8a5f9d267166f717e2f3947c /plugins/colored-man-pages/colored-man-pages.plugin.zsh
parent058885f5263f29f046c96ea2ecf55e6dca3ed321 (diff)
parent88b3f028f4a2ffa4f3853a11e4b8e0d78008ca34 (diff)
downloadzsh-3aaa0bc62ece494dd2b6e47a191de79e562156f9.tar.gz
zsh-3aaa0bc62ece494dd2b6e47a191de79e562156f9.tar.bz2
zsh-3aaa0bc62ece494dd2b6e47a191de79e562156f9.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/colored-man-pages/colored-man-pages.plugin.zsh')
-rw-r--r--plugins/colored-man-pages/colored-man-pages.plugin.zsh73
1 files changed, 41 insertions, 32 deletions
diff --git a/plugins/colored-man-pages/colored-man-pages.plugin.zsh b/plugins/colored-man-pages/colored-man-pages.plugin.zsh
index ec518472c..37faed672 100644
--- a/plugins/colored-man-pages/colored-man-pages.plugin.zsh
+++ b/plugins/colored-man-pages/colored-man-pages.plugin.zsh
@@ -1,39 +1,48 @@
-if [[ "$OSTYPE" = solaris* ]]
-then
- if [[ ! -x "$HOME/bin/nroff" ]]
- then
- mkdir -p "$HOME/bin"
- cat > "$HOME/bin/nroff" <<EOF
-#!/bin/sh
-if [ -n "\$_NROFF_U" -a "\$1,\$2,\$3" = "-u0,-Tlp,-man" ]; then
- shift
- exec /usr/bin/nroff -u\$_NROFF_U "\$@"
-fi
-#-- Some other invocation of nroff
-exec /usr/bin/nroff "\$@"
-EOF
- chmod +x "$HOME/bin/nroff"
- fi
-fi
+# 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}"
function colored() {
- command env \
- LESS_TERMCAP_mb=$(printf "\e[1;31m") \
- LESS_TERMCAP_md=$(printf "\e[1;31m") \
- LESS_TERMCAP_me=$(printf "\e[0m") \
- LESS_TERMCAP_se=$(printf "\e[0m") \
- LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
- LESS_TERMCAP_ue=$(printf "\e[0m") \
- LESS_TERMCAP_us=$(printf "\e[1;32m") \
- PAGER="${commands[less]:-$PAGER}" \
- _NROFF_U=1 \
- PATH="$HOME/bin:$PATH" \
- "$@"
+ 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 "$@"
}
# Colorize man and dman/debman (from debian-goodies)
function man \
- dman \
- debman {
- colored $0 "$@"
+ dman \
+ debman {
+ colored $0 "$@"
}