Search code examples
linuxshelltcshmanpage

Colored manpages with tcsh?


I really like the colored manpages which can are achieved by

export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

in your .bashrc or .zshrc. My question is: How do I export these variables in tcsh? I have to use tcsh at work and cannot get it working. I tried plenty of variations, but nothing worked. Simply replacing export with setenv and = with " " doesn't do the trick. But it should work somehow. If i start a tcsh out of my zsh with this exports set I can enjoy colored manpages in tcsh, also. But that's an ugly workaround.


Solution

  • The problem is that tcsh isn't interpreting the escape sequence in your variable name, so the environment variable ends up with a literal \E in it when you try to set it with tcsh. Here's one way you can get around that, using Bash to interpret the escape sequences, although it's a little ugly:

    % setenv LESS_TERMCAP_md `bash -c 'echo -en "\e[01;31m"'`
    % setenv LESS_TERMCAP_me `bash -c 'echo -en "\e[0m"'`
    % setenv LESS_TERMCAP_se `bash -c 'echo -en "\e[0m"'`
    % setenv LESS_TERMCAP_so `bash -c 'echo -en "\e[01;44;33m"'`
    % setenv LESS_TERMCAP_ue `bash -c 'echo -en "\e[0m"'`
    % setenv LESS_TERMCAP_us `bash -c 'echo -en "\e[01;32m"'`