PDA

View Full Version : ls --colour; i.e. ls for non-Americans


Darwin Award Winner
January 31st, 2008, 11:22 PM
If you think the correct spelling of "color" is "colour," then here's a script to make the ls program agree with you:

#!/usr/bin/perl
foreach(0..$#ARGV) {
last if $ARGV[$_] eq "--";
$ARGV[$_] =~ s/^--colour/--color/;
}
exec("/bin/ls",@ARGV);

Put that in a text file called "ls", make it executable, and put it in your path somewhere before /bin (i.e. before the location of the real ls), and then start a new terminal to allow the path change to take effect.

Now, try ls --colour=yes

Enjoy!

Note: You could make a copy of this script for any other program that takes the --color option, such as grep. If there is demand for it, I will make a generalized script for any executable.

wavesound
February 3rd, 2008, 07:57 PM
Nice one
Bet you couldn't get bill gates to do that!!!

cheers
Bob

~LoKe
February 3rd, 2008, 08:43 PM
That's a little excessive. Just make an alias in your ~/.bashrc that reads:
alias ls --colour='ls --color=auto'

EDIT: Apparently you'd can't do that. Dumb.

Darwin Award Winner
February 4th, 2008, 02:29 AM
Even if that did work, it wouldn't cover something like
ls -ld ~/Downloads --colour
Also, would anyone be interested in a more general implementation of this? This would mean support for more commands (e.g. grep --colour) and more options (can't think of any examples).