Colorize man XXX.
This plugin will do nothing without dependencies.
Download *.deb firstly.
deb -i *.debDownload *.rpm firstly.
rpm -i *.rpmyay -S sh-manpagernix-env -iA nur.repos.Freed-Wu.manpagersudo add-apt-repository ppa:freedwu/ppa
sudo apt update
sudo apt install manpagerbrew tap Freed-Wu/manpager https://github.com/Freed-Wu/manpager
brew install manpagerAdd 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 XXXbyexport LESSOPEN='|lesspipe.sh %s'. - bat-extras: provide a program named
batmanand user canbatman XXXto get colorizedman XXX. Right, you canalias man=batmanto colorizeman XXX. However:- Not every shell has aliases, such as
!man XXXonptpython/ipython manhas shell completions,batmandoesn't have.
- Not every shell has aliases, such as
There are two different realizations of man:
- man-db: the common
manused by most distributions. - mandoc: the lightweight but not enough powerful
manused 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
-manpagerforsys-apps/man-dbto avoid installing it
