[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Colorful Less, etc.



You can set an environment variable, LESS, to whatever options you want `less` to use.  To enable color you use the -R option so would do:

export LESS=-R

Put this in your ~/.bashrc or whatever.

Here's an example... We tell `grep` to color output "always" since normally it won't color piped output and then we set (or unset) the LESS environment variable:

$ grep --color=always color <(man less)  | LESS=-R \less

$ grep --color=always color <(man less)  | LESS= \less

That is actually using a couple other tricks.  At least in Bash, \less prevents an alias for less from being used instead of the command; I believe it is equivalent to `command less`.  <(some_command) make a pseudo-file for the output of some_command.  One common case for <(some_command) is to diff files after I'm transformed them a bit, for example,

diff -u <(grep -v ^Date file_a) <(grep -v ^Date file_b)

Or another one is to open *many* files in vim in a semi-sane way:

vim -q <(ls *.txt)

This exploits Vim's quickfix window to keep a list of the files.  You can then use :copen, :cp, :cn to navigate them.

-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.