Ubuntu: How to get color man pages under fish shell?



Question:

There seems to be a way to get man pages to display in color (see here. It involves setting environment variables associated with less and adding these definitions to .bashrc. I tried doing the same in config.fish for the fish shell, but got no color output.

How to get color man pages in the fish shell?


Solution:1

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")    


Solution:2

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 env, 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 (printf "\e[1;31m")    # end of all formatting:    set -x LESS_TERMCAP_me (printf "\e[0m")      # start of standout (inverted):    #set -x LESS_TERMCAP_so (printf "\e[1;40;92m")    # end of standout (inverted):    #set -x LESS_TERMCAP_se (printf "\e[0m")    # (no change â€" I like the default)      # start of underline:    #set -x LESS_TERMCAP_us (printf "\e[1;32m")    # end of underline:    #set -x LESS_TERMCAP_ue (printf "\e[0m")    # (no change â€" I like the default)      env man $argv  end  


Solution:3

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"  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »