tags:

views:

443

answers:

5

Is it possible to "alias" all commands to append --color? Or instead have it automatically activated for every program that supports it?

+1  A: 

How would the shell know automatically which programs support the --color option? You'd have to give it a list, and as long as you're going to do that you might as well just give it a list of alias commands to run. I suppose it could be done programmatically by something like this (in bash):

for cmd in ls blah foo; do
    alias "$cmd=$cmd --color"
done
David Zaslavsky
A: 

There are really very few programs that support the --color option, and they aren't actually written by a single organization. Thus, they don't refer to a central location for their options. Heck, the don't even have a uniform argument set, so just the --color option to the end of every command would probably cause a lot of damage!

I'm afraid you'd have to alias each and one. For example, for ls:

alias ls='ls --color'
scraimer
+2  A: 

You should be careful with this, especially when chaining invocations.

grep --color=yes 'foo' bar.txt | less   #leads to weird ANSI stuff in output
grep --color=yes 'foo' bar.txt | less -R #binary codes interpreted as colors

Basically, this can screw up pipelining...I'd recommend aliasing things with colorized output to separate commands to avoid doing "cmd | myprog" and getting weird results due to embedded ANSI.

ramanujan
Most commands have --color=tty for this purpose
Joshua
Some commands (such as grep) support '--color=auto' which will colorize the output if and only if stdout is a terminal. If stdout is a pipe, they will not colorize.
Adam Rosenfield
A: 

instead of trying to change each command

why not just change the way your console displays colors

drfrog
Change the console how? To make it magically display colors for text that the command didn't mark up?
Rob Kennedy