Colorize man XXX
.
This plugin will do nothing without dependencies.
Download *.deb
firstly.
deb -i *.deb
Download *.rpm
firstly.
rpm -i *.rpm
yay -S sh-manpager
nix-env -iA nur.repos.Freed-Wu.manpager
sudo add-apt-repository ppa:freedwu/ppa
sudo apt update
sudo apt install manpager
brew tap Freed-Wu/manpager https://github.com/Freed-Wu/manpager
brew install manpager
Add the following code to your .bash_profile
, .zprofile
, ...
eval "$(manpager)"
You can define $MANPAGER
to customize the colorization of man XXX
.
Such as:
export MANPAGER='manpager --paging=never'
export MANPAGER='manpager | less --pattern=^\\S+'
That is because man XXX
looks like
MAN(1) Manual pager utils MAN(1)
NAME
man - an interface to the system reference manuals
SYNOPSIS
man [man options] [[section] page ...] ...
...
DESCRIPTION
man is the system's manual pager. Each page argument given to man is
...
So we can search ^\S+
forward and backward to jump between the lines started
with NAME
, SYNOPSIS
, DESCRIPTION
, etc.
You can man XXX | manpager
to force to colorize man XXX
.
- zsh-help: colorize
XXX --help
. - lesspipe: colorize
less XXX
byexport LESSOPEN='|lesspipe.sh %s'
. - bat-extras: provide a program named
batman
and user canbatman XXX
to get colorizedman XXX
. Right, you canalias man=batman
to colorizeman XXX
. However:- Not every shell has aliases, such as
!man XXX
onptpython/ipython
man
has shell completions,batman
doesn't have.
- Not every shell has aliases, such as
There are two different realizations of man
:
- man-db: the common
man
used by most distributions. - mandoc: the lightweight but not enough powerful
man
used by:
So, our manpager
must be compatible for both of them. There are some
differences between them:
- For
export MANPAGER="sh -c 'col -bx | bat -plman'"
:- man-db will split it to get
["sh", "-c", "col -bx | bat -plman"]
. - mandoc will split it to get
["sh", "-c", "'col", "-bx", "|", "bat", "-plman"]
. How terrible!
- man-db will split it to get
- For
MANPAGER='manpager --option' man foobar
:- man-db will execute
MANPAGER='' man foobar | manpager --option
. Yes, there exists a pipe. - mandoc will generate a temp file
/tmp/man.XXXX??????
which?
is a random alphabet as the output ofman foobar
, then executemanpager --option /tmp/man.XXXX??????
- man-db will execute
So we use [ -t 0 ]
to judge current man
is which man
, then wrap it.
- gentoo manpager:
add
-manpager
forsys-apps/man-db
to avoid installing it