11

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.

imgx64
  • 508
  • 1
  • 5
  • 15

3 Answers3

12

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

$ lesskey -
#env
LESS = -R

Then Ctrl+d

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

imgx64
  • 508
  • 1
  • 5
  • 15
4

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

Gilles 'SO- stop being evil'
  • 69,786
  • 21
  • 137
  • 178
  • 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 05: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 'SO- stop being evil' Aug 11 '10 at 07: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: http://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 'SO- stop being evil' 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
1

The most likely issue is that you didn't export the less variable.

LESS="FRX"
ls -l | less
<not colorized>

export LESS="FRX"
ls -l | less
<colorized>

You could, for example, create a file called '/etc/profile.d/less.sh', with just 'export LESS="FRX"' in it, and your less configuration will be available system-wide.

slm
  • 9,959
  • 10
  • 49
  • 57
Mr. B
  • 111
  • 3