[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Colorful Less, etc.
- To: silug-discuss@silug.org
- Subject: Colorful Less, etc.
- From: Nathan Nutter <iam@nnutter.com>
- Date: Thu, 6 Feb 2014 00:21:31 -0600
- DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=from:content-type:content-transfer-encoding:subject:message-id:date:to:mime-version; s=smtpout; bh=yuWVPxGdvBDwZjs9RvvRo70zx+o=; b=L1D1EbYILNYUBrOzcEdkVxf/jVY/clpMBoJUTqcvCwd286EPL3/1YsjOKrdI8DmnR1yZRG8alvUMutbjph8hh35sfI2M3ljgSw4MX8mGmXnh6rFofr237+BzDo9wgbLXb7zmTuR/V1bwylavnGzU5BNx7si8lPV8ISD4L0VfQps=
- Organization: Southern Illinois Linux Users Group
- Reply-To: silug-discuss@silug.org
- Sender: silug-discuss-owner@silug.org
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.