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?


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")  
| improve this answer | |

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:

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
| improve this answer | |
  • 2
    Awesome thanks! And to get even more fishy you can use the set_color command. e.g.: set -x LESS_TERMCAP_md (set_color -o red), set -x LESS_TERMCAP_me (set_color normal) – Chris Clark Apr 13 '17 at 12:36

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"
| improve this answer | |
  • Not working. I see the \e[01 strings when I do "man ls". – Ashwin Nanjappa Oct 28 '14 at 14:44
  • Strange, I believe this was straight from my config file. I haven't actually tried it on Ubuntu, though, as I run a different distro myself. Maybe you could try adding set -x LESS="-R" to the end of your config? – bobbaluba Oct 29 '14 at 8:07
  • Adding that did not help. Still seeing same \e[01 strings in manpage. – Ashwin Nanjappa Oct 29 '14 at 9:38

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)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.