Linux Tip: Color enabled pager - less

Recently I was using a command line tool which was generating many lines of color text. The output was displayed so fast on my xterm, that I couldn't read it. So I thought, that I could use "| less" pager to see what's up, and I was wrong :( - less "out of the box" doesn't support colors. I've tried most pager but I prefer less.

... but there is a way!

Less doesn't support colors "as it is", but there are some hacks. Thanks rha7dotcom.
export LESS="-RSM~gIsw"
  • R - Raw color codes in output (don't remove color codes)
  • S - Don't wrap lines, just cut off too long text
  • M - Long prompts ("Line X of Y")
  • ~ - Don't show those weird ~ symbols on lines after EOF
  • g - Highlight results when searching with slash key (/)
  • I - Case insensitive search
  • s - Squeeze empty lines to one
  • w - Highlight first line after PgDn
Remember the tip with export LESS works only if you software you want to page uses RAW ASCII colors not those ncursed based!

Color man pages using less pager

Thanks Nion
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'
To make it available for full time add this entries to your ~/.bashrc or ~/.${SHELL}rc. Hope this helps someone.

1 komentarzy:

0x1fff 19 Nov 2009 12:16:00  

I've found that colour highlighting on console can be difficult :(

If you want to color src preview via less, do something like:

alias vless='/usr/share/vim/vimcurrent/macros/less.sh'

and use vless instead less.

If you don't like vim, you can try to use tip provided by Peter Eisentraut (command line syntax highlight using source-highlight, or command line syntax highlighting using highlight)

Post a Comment

About Me

Archiwum

Labels

Creative Commons License
This work is in the Public Domain.