I do use aliases to turn on color for some commands by default. But I'm wondering if there's an easier way at telling my system, color is supported, don't make me use --color
for grep
, ls
, etc.
2 Answers
FreeBSD has CLICOLOR.
On Linux and any other system with GNU tools, you need to set LS_COLORS, GREP_COLOR, and GREP_OPTIONS='--color=auto', but even then you still need to run ls --color=auto
. Run info coreutils 'ls invocation'
for more details.
The easiest way I know to avoid typing --color
on Linux is to make ls
run ls --color=auto
using an alias.
This is what I put in my .bashrc (well, really my .env, but it's like .bashrc) to make it happen by default:
# set default flags
if grep --color=auto --quiet "" "$HOME"/.bashrc >/dev/null 2>&1
then
alias grep='grep --color=auto'
fi
if ls --color=never --directory / >/dev/null 2>&1
then
# enable colors with GNU ls
alias ls='ls --color=auto'
else
alias ls='ls -F'
fi
-
3
There isn't a standard for forcing colours.
CLICOLOR
is increasingly common, and there's an attempt to standardise it too.
You can alias commands to provide the --color=auto
(or equivalent) flag by default in your .bashrc
, but you'll need to find the relevant flag for each command.