Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 854
skorgon Avatar asked Feb 08 '11 05:02

skorgon


2 Answers

The way to do this which is native to tcsh and is portable to different terminal types is to use the echotc builtin command:

setenv LESS_TERMCAP_mb `echotc md; echotc AF 1`
setenv LESS_TERMCAP_md `echotc md; echotc AF 1`
setenv LESS_TERMCAP_me `echotc me`
setenv LESS_TERMCAP_se `echotc me`
setenv LESS_TERMCAP_so `echotc md; echotc AF 3; echotc AB 4`
setenv LESS_TERMCAP_ue `echotc me`
setenv LESS_TERMCAP_us `echotc md; echotc AF 2`

See man 5 terminfo for the termcap codes and color codes.

md is enter_bold_mode
me is exit_attribute_mode
AF is set_a_foreground
AB is set_a_background

By the way, to do this in Bash, use the external utility tput and the terminfo capability names:

export LESS_TERMCAP_mb=$(tput bold; tput setaf 1)
export LESS_TERMCAP_md=$(tput bold; tput setaf 1)
export LESS_TERMCAP_me=$(tput sgr0)
export LESS_TERMCAP_se=$(tput sgr0)
export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4)
export LESS_TERMCAP_ue=$(tput sgr0)
export LESS_TERMCAP_us=$(tput bold; tput setaf 2)
like image 79
Dennis Williamson Avatar answered Sep 28 '22 07:09

Dennis Williamson


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"'`
like image 30
Adam Rosenfield Avatar answered Sep 28 '22 07:09

Adam Rosenfield