Awesome
manpager
Colorize man XXX
.
Dependencies
This plugin will do nothing without dependencies.
Install
deb
Download *.deb
firstly.
deb -i *.deb
rpm
Download *.rpm
firstly.
rpm -i *.rpm
AUR
yay -S sh-manpager
NUR
nix-env -iA nur.repos.Freed-Wu.manpager
PPA
sudo add-apt-repository ppa:freedwu/ppa
sudo apt update
sudo apt install manpager
homebrew
brew tap Freed-Wu/manpager https://github.com/Freed-Wu/manpager
brew install manpager
Configure
Add the following code to your .bash_profile
, .zprofile
, ...
eval "$(manpager)"
Customize
You can define $MANPAGER
to customize the colorization of man XXX
.
Such as:
Disable Paging
export MANPAGER='manpager --paging=never'
Define n
and p
to Jump Forward and Backward Between Sections
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.
Force to Colorize man XXX
You can man XXX | manpager
to force to colorize man XXX
.
Similar Projects
- 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
Details under the Hood
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.
Related Projects
- gentoo manpager:
add
-manpager
forsys-apps/man-db
to avoid installing it