How to get color man pages under fish shell?
If you want these colors to be added only when viewing man pages, not for everything you view in less
, you should set these variables in a wrapper function for man
instead of putting them in your config.fish
.
The whole process is to create a new file at ~/.config/fish/functions/man.fish
, and inside it define a function man
that sets the necessary environment variables, then calls the original man
using command
, passing in arguments using $argv
.
This is my version of the wrapper function:
~/.config/fish/functions/man.fish
function man --description "wrap the 'man' manual page opener to use color in formatting"
# based on this group of settings and explanation for them:
# http://boredzo.org/blog/archives/2016-08-15/colorized-man-pages-understood-and-customized
# converted to Fish shell syntax thanks to this page:
# http://askubuntu.com/questions/522599/how-to-get-color-man-pages-under-fish-shell/650192
# start of bold:
set -x LESS_TERMCAP_md (set_color --bold red)
# end of all formatting:
set -x LESS_TERMCAP_me (set_color normal)
# start of standout (inverted colors):
#set -x LESS_TERMCAP_so (set_color --reverse)
# end of standout (inverted colors):
#set -x LESS_TERMCAP_se (set_color normal)
# (no change – I like the default)
# start of underline:
#set -x LESS_TERMCAP_us (set_color --underline)
# end of underline:
#set -x LESS_TERMCAP_ue (set_color normal)
# (no change – I like the default)
command man $argv
end
You can set the configuration by the following commands,
set -x LESS_TERMCAP_mb (printf "\033[01;31m")
set -x LESS_TERMCAP_md (printf "\033[01;31m")
set -x LESS_TERMCAP_me (printf "\033[0m")
set -x LESS_TERMCAP_se (printf "\033[0m")
set -x LESS_TERMCAP_so (printf "\033[01;44;33m")
set -x LESS_TERMCAP_ue (printf "\033[0m")
set -x LESS_TERMCAP_us (printf "\033[01;32m")
Assuming you use less as your pager, put this in ~/.config/fish/config.fish
:
set -x LESS_TERMCAP_mb (printf "\e[01;31m")
set -x LESS_TERMCAP_md (printf "\e[01;31m")
set -x LESS_TERMCAP_me (printf "\e[0m")
set -x LESS_TERMCAP_se (printf "\e[0m")
set -x LESS_TERMCAP_so (printf "\e[01;44;33m")
set -x LESS_TERMCAP_ue (printf "\e[0m")
set -x LESS_TERMCAP_us (printf "\e[01;32m")
If you see \e[0m
etc appearing when you view the man page, try adding this line as well:
set -x LESS "-R"
It's possible to use set_color
instead of direct ANSI sequences. In fact, this allows you to use any color you want, by using 24-bit color hexadecimal escapes, like (set_color FF55AA)
.
set -x LESS_TERMCAP_mb (set_color brred)
set -x LESS_TERMCAP_md (set_color brred)
set -x LESS_TERMCAP_me (set_color normal)
set -x LESS_TERMCAP_se (set_color normal)
set -x LESS_TERMCAP_so (set_color -b blue bryellow)
set -x LESS_TERMCAP_ue (set_color normal)
set -x LESS_TERMCAP_us (set_color brgreen)