summaryrefslogtreecommitdiff
path: root/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh
diff options
context:
space:
mode:
authorAditya <bluenerd@protonmail.com>2023-02-27 20:04:56 +0530
committerAditya <bluenerd@protonmail.com>2023-02-27 20:04:56 +0530
commitedc449275b6c04445f58b108ca0937a87c1e8430 (patch)
tree9fd484d58145b616f29a78857cc0b1c8b1c18f05 /oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh
parent6f5424ca96c4221ef433f545642669e9c104d0ed (diff)
add zsh
Diffstat (limited to 'oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh')
-rw-r--r--oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh53
1 files changed, 53 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh b/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh
new file mode 100644
index 0000000..981992d
--- /dev/null
+++ b/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh
@@ -0,0 +1,53 @@
+# 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}"
+
+# Handle $0 according to the standard:
+# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
+0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
+0="${${(M)0:#/*}:-$PWD/$0}"
+
+# Absolute path to this file's directory.
+typeset -g __colored_man_pages_dir="${0:A:h}"
+
+function colored() {
+ 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 "$@"
+}