Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

The following command gives me in the pager Most/Less

man -k background

alt text

The picture has everything in green, even descriptions. I would like to set them yellow.

How can you have set the descriptions yellow in Less/Most by Less_termcap?


My variables which affect Less

     export LESS_TERMCAP_mb=$'\E[01;31m'         # begin blinking
     export LESS_TERMCAP_md=$'\E[01;38;5;74m'    # bold in blue
     export LESS_TERMCAP_me=$'\E[0m'        # end mode

     export LESS_TERMCAP_se=$'\E[0m'        # end standout-mode
     export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box
     export LESS_TERMCAP_ue=$'\E[0m'        # end underline

     export LESS_TERMCAP_us=$'\E[04;33;146m'    # begin underline is now yellow
     #                             |  |  |
     #                             |  |----------------- yellow
     #                             |-------------------- underline

     # to have the indication of cursor's location and line numbers
     export LESS="-mN"
share|improve this question

3 Answers 3

up vote 4 down vote accepted

This will do the trick:

man -k background|sed "s/ - \(.*\)/ - \o033[33m\1\o033[0m/"

You could do a function:

mank () { man -k $1|sed "s/ - \(.*\)/ - \o033[33m\1\o033[0m/"; }

Then you could do:

mank background

and the commands would be in your default color and the descriptions would be yellow. The "33" after the square bracket stands for yellow. You can substitute another number for another color. One place to get a list of colors and their codes is man 5 dir_colors.

And, of course, you have to use less -R (or set $LESS to include it) to see the colors in less.

Here is a more portable version that uses tput:

mank() { local yellow=$(tput setaf 3) default=$(tput op); /usr/bin/man -k $1|sed "s/ - \(.*\)/ - ${yellow}\1${default}/"; }

See man tput and man 5 terminfo (in the "Color Handling" section) for more info, including a list of color numbers that setaf understands.

share|improve this answer
    
@Dennis: Please, see my answer at the bottom. –  Masi Jul 3 '09 at 15:58

Answer to Dennis' answer

The following command does not put colors to the output

mank() {
/usr/bin/man -k $1|sed "s/ - \(.*\)/ - \o033[33m\1\o033[0m/" > /tmp/manual2; less /tmp/manual2
}
share|improve this answer
1  
It works for me. Do you have -R in your LESS environment variable? I notice that it's not included in the less command here. Also, why are you creating a temporary file? Why not just pipe the output of sed into less? –  Dennis Williamson Jul 4 '09 at 15:24
    
The answer to your last question is this stackoverflow.com/questions/1049350/… –  Masi Jul 4 '09 at 15:31
    
@Dennis: It seems that I do not have the option in my LESS env variable. Please, see my edit in my question. –  Masi Jul 4 '09 at 15:34
    
How can you set the -R in your LESS environment variable? –  Masi Jul 4 '09 at 15:34
    
The new question is at serverfault.com/questions/35887/… –  Masi Jul 4 '09 at 15:36

Answer to Dennis' edit

The following code works also great

mank() { 
         local yellow=$(tput setaf 3) default=$(tput op)                                                                                                   
         /usr/bin/man -k $1 | sed "s/ - \(.*\)/ - ${yellow}\1${default}/" > /tmp/manual2
         less -f /tmp/manual2
     }

Thank you for your answers!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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