From e8f4457a841a78e641d337705a03bb052fcb2213 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Tue, 1 Oct 2024 21:53:16 -0400 Subject: [PATCH] colored_man_pages: Update to use local variables --- plugins/colored-man-pages/README.md | 11 ++++- .../colored-man-pages.plugin.sh | 47 ++++++++++++++----- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/plugins/colored-man-pages/README.md b/plugins/colored-man-pages/README.md index 8ad050aaa..e0b843528 100644 --- a/plugins/colored-man-pages/README.md +++ b/plugins/colored-man-pages/README.md @@ -4,6 +4,15 @@ Adds colors to [`man`](https://man7.org/linux/man-pages/man1/man.1.html) pages. To use it, add `colored-man-pages` to the plugins array in your .bashrc file. -``` +```bash plugins=(... colored-man-pages) ``` + +It will also automatically colorize man pages displayed by `dman` or `debman`, +from [`debian-goodies`](https://packages.debian.org/stable/debian-goodies). + +You can also try to color other pages by prefixing the respective command with `colored`: + +```bash +colored git help clone +``` diff --git a/plugins/colored-man-pages/colored-man-pages.plugin.sh b/plugins/colored-man-pages/colored-man-pages.plugin.sh index dd988817a..55d63bffd 100644 --- a/plugins/colored-man-pages/colored-man-pages.plugin.sh +++ b/plugins/colored-man-pages/colored-man-pages.plugin.sh @@ -1,16 +1,41 @@ #! bash oh-my-bash.module +# +# Colored Man Pages Plugin +# +# This plugin is based on the following Oh-My-Zsh plugin: +# https://github.com/ohmyzsh/ohmyzsh/blob/6bc4c80c7db072a0d2d265eb3589bbe52e0d2737/plugins/colored-man-pages/colored-man-pages.plugin.zsh -# Bold and Blinking -export LESS_TERMCAP_mb=$_omb_term_green -export LESS_TERMCAP_md=$_omb_term_bold_green -export LESS_TERMCAP_me=$_omb_term_reset +# Adds the LESS_TERMCAP_* variables to the environment to color man pages. +function colored() { + local -a environment -# Standout Mode -export LESS_TERMCAP_so=$_omb_term_olive -export LESS_TERMCAP_se=$_omb_term_reset + environment+=( LESS_TERMCAP_mb=${_omb_term_red} ) + environment+=( LESS_TERMCAP_md=${_omb_term_bold_red} ) + environment+=( LESS_TERMCAP_me=${_omb_term_reset} ) + environment+=( LESS_TERMCAP_so=${_omb_term_bold_yellow} ) + environment+=( LESS_TERMCAP_se=${_omb_term_reset} ) + environment+=( LESS_TERMCAP_us=${_omb_term_bold_green} ) + environment+=( LESS_TERMCAP_ue=${_omb_term_reset} ) -# Underline -export LESS_TERMCAP_us=$_omb_term_purple -export LESS_TERMCAP_ue=$_omb_term_reset + # Prefer `less` whenever available, since we specifically configured + # environment for it. + environment+=( PAGER="${commands[less]:-$PAGER}" ) + environment+=( GROFF_NO_SGR=1 ) -# Extra Styles + env "${environment[@]}" "$@" +} + +# Wrapper for man to colorize the output. +function man { + colored man "$@" +} + +# Wrapper for dman to colorize the output. +function dman { + colored dman "$@" +} + +# Wrapper for debman to colorize the output. +function debman { + colored debman "$@" +}