Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins: Add colored-man-pages plugin #619

Merged
merged 15 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```
44 changes: 44 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,44 @@
#! 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 the environment to color man pages.
function colored() {
local -a environment

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_green} )
environment+=( 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 )

env "${environment[@]}" "$@"
}

# 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 dman "$@"
RobLoach marked this conversation as resolved.
Show resolved Hide resolved
}

# Wrapper for debman to colorize the output.
_omb_util_binary_exists debman &&
function debman {
colored debman "$@"
RobLoach marked this conversation as resolved.
Show resolved Hide resolved
}
Loading