Skip to content

Commit

Permalink
colored_man_pages: Update to use local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Oct 2, 2024
1 parent 605e749 commit e8f4457
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
11 changes: 10 additions & 1 deletion plugins/colored-man-pages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
47 changes: 36 additions & 11 deletions plugins/colored-man-pages/colored-man-pages.plugin.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
}

0 comments on commit e8f4457

Please sign in to comment.