Skip to content

Commit

Permalink
plugins: Add "colored-man-pages" plugin (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach authored Oct 2, 2024
1 parent f53beb6 commit e712342
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
18 changes: 18 additions & 0 deletions plugins/colored-man-pages/README.md
Original file line number Diff line number Diff line change
@@ -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
```
42 changes: 42 additions & 0 deletions plugins/colored-man-pages/colored-man-pages.plugin.sh
Original file line number Diff line number Diff line change
@@ -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" "$@"
}

0 comments on commit e712342

Please sign in to comment.