diff --git a/plugins/README.md b/plugins/README.md index 350ec6e3d..a4e0df249 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -33,6 +33,7 @@ By leveraging these plugins, you can streamline your workflow and tackle coding | battery | Plugin related to monitoring and managing battery on computer systems. | | brew | Package manager for macOS and Linux facilitating software installation and management. | | bu | Insufficient information provided to give a precise description. | +| colored-man-pages | Adds a few colors to `man` pages. | chezmoi | Dotfile management tool enabling management of user environment configuration. | | dotnet | This plugin provides completion and useful aliases for .NET Core CLI. | | fasd | Utility easing filesystem navigation through shortcuts and abbreviated commands. | diff --git a/plugins/colored-man-pages/README.md b/plugins/colored-man-pages/README.md new file mode 100644 index 000000000..e0b843528 --- /dev/null +++ b/plugins/colored-man-pages/README.md @@ -0,0 +1,18 @@ +# Colored Man Pages Plugin + +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 new file mode 100644 index 000000000..50d809061 --- /dev/null +++ b/plugins/colored-man-pages/colored-man-pages.plugin.sh @@ -0,0 +1,42 @@ +#! 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 + +# Adds the LESS_TERMCAP_* variables to color the man pages. +function colored { + local -x LESS_TERMCAP_mb=$_omb_term_red + local -x LESS_TERMCAP_md=$_omb_term_bold_red + local -x LESS_TERMCAP_me=$_omb_term_reset + local -x LESS_TERMCAP_so=$_omb_term_bold_yellow + local -x LESS_TERMCAP_se=$_omb_term_reset + local -x LESS_TERMCAP_us=$_omb_term_green + local -x LESS_TERMCAP_ue=$_omb_term_reset + + # Prefer `less` whenever available, since we specifically configured + # environment for it. + local -x PAGER=$(type -P less || _omb_util_print "$PAGER") + local -x GROFF_NO_SGR=1 + + command "$@" +} + +# Wrapper for man to colorize the output. +_omb_util_binary_exists man && + function man { + colored "$FUNCNAME" "$@" + } + +# Wrapper for dman to colorize the output. +_omb_util_binary_exists dman && + function dman { + colored "$FUNCNAME" "$@" + } + +# Wrapper for debman to colorize the output. +_omb_util_binary_exists debman && + function debman { + colored "$FUNCNAME" "$@" + }