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"

Meaning of each character:

  • 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.

Comments

comments powered by Disqus