1

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

1

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

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

Comments

1

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'

Comments

-1

instead of trying to change each command

why not just change the way your console displays colors

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.