I'm using Ubuntu 10.04. My default pager(set using update-alternatives, not $PAGER) is less. The problem is, when I use ri(Ruby documentation tool) with the '-f ansi' mode, less shows the escape sequences(such as 'ESC[36m') instead of displaying the text in color. I can force it to show colors by manually piping the output to less with the -R option, for example:

ri -f ansi String | less -R

However, I'd like this to be the default option when less is used as a pager.

Note: I'm aware that more and most show colors by default, but I use less because of the vi-like key bindings.

link|improve this question
feedback

2 Answers

up vote 2 down vote accepted

I found the answer somewhere else. I needed to use lesskey to set up less's options:

$ lesskey -
#env
LESS = -R
^d

did the trick. I'm still not sure why less ignores $LESS though.

link|improve this answer
Aha! the options in ~/.less (which is what lesskey writes) override those in the environment. So you must have had a .less file containing LESS=-r before. – Gilles Aug 11 '10 at 11:56
feedback

Set the LESS environment variable to a space-separated list of your favorite options.

link|improve this answer
Didn't work, less totally ignores $LESS. I'm guessing this is an Ubuntu-specific issue, since many other shell variables are ignored, including $PAGER and $EDITOR. – imgx64 Aug 11 '10 at 5:15
less definitely takes $LESS into account, on Ubuntu 10.04 like everywhere else. And $PAGER and $EDITOR work too. It sounds like you're not setting the environment variables properly. How did you do it? – Gilles Aug 11 '10 at 7:15
I tried this: "export LESS='-R'; ri -f ansi String | less" However, less does use other environment variables correctly, such as the ones mentioned here: crunchbanglinux.org/forums/topic/2403/color-man-pages – imgx64 Aug 11 '10 at 10:01
@imgx64: It Works For Me™, and I don't see how it could not work. Hmmm... What is the output of the two commands type less and env | grep LESS? – Gilles Aug 11 '10 at 10:25
"less is /usr/bin/less" and " LESS=-R LESSOPEN=| /usr/bin/lesspipe %s LESSCLOSE=/usr/bin/lesspipe %s %s " – imgx64 Aug 11 '10 at 11:06
feedback

Your Answer

 
or
required, but never shown

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