[Ilugc] using cat to print in a color scheme
steve at lonetwin.net
Tue Feb 17 02:56:35 IST 2009
Satish Eerpini wrote:
> Is it possible to 'cat' a file to the terminal in a particular color
> scheme, say like the color scheme used by vim or something.
> I mean instead of getting plain text when we run say :
> cat foo.c
> , can we obtain the output in a particular color scheme in the
> terminal ? Is this possible ??
Well, "cat" a tool for concatenating files. It does not know (or care) where it
is cat-ing to (for that matter, it does not know or care, where it is cat-ing
from either -- and still, or probably because of this, it is one of the most
useful commands in the unix toolbox)
OTOH, Pagers (like 'more' or 'less') are tools to view files on the terminal.
That said, vim also behaves somewhat like a pager when invoked using the command
'view'. However, this does not do syntax highlighting, nor does it take input
from stdin (ie: executing "cat /some/file | view" does not do what you expect)
So, to view a file with syntax highlighting, you can use a vim trick.
- Look for the file /usr/share/vim/vim*/macros/less.sh
- create an alias for that script:
$ alias vless='/usr/share/vim/vim<version>/macros/less.sh'
(you may also save the alias in ~/.bashrc if you like)
- now use vless as you would use less
$ vless foo.c
$ cat /some/file | some_filter | vless
Linux Centric Marketplace: http://www.tuxcompatible.com
More information about the ilugc