How to change the default --color preference for "ls' on Windows?

4

I'm using ls (from Msys) on Windows. By default, ls doesn't colour-code directories and archives, but that's something I want. I'm tired of typing "ls -C" and "ls --color". Is there any way apart from setting up a bash script that will let me do this. (Remember, I'm on Windows)

aviraldg

Posted 2009-10-14T16:24:29.297

Reputation: 2 059

Answers

6

doskey ls=ls --color $*

doskey is built-in, even!

I have a startup .bat file that acts as sort-of a .bashrc, and throw all my aliases in there, as well as having a small Python script to manage them more easily. cmd is really very bearable with a few additional tools (Cygwin goes a long way, just add its \bin to your PATH)


To apply aliases automatically with each new instance of cmd, create a .bat file, for example at %USERPROFILE%\aliases.bat with this content:

@ECHO OFF
doskey ls=ls --color $*

Then, using regedit, locate HKEY_CURRENT_USER\Software\Microsoft\Command Processor\ and add a String Value named Autorun, with Value data set to: %USERPROFILE%\aliases.bat

Phoshi

Posted 2009-10-14T16:24:29.297

Reputation: 22 001

Um... how do I get this to work permanently with all instances of cmd.exe? – aviraldg – 2009-10-14T17:24:02.967

2That's what the .config file is for. HKEY_CURRENT_USER\Software\Microsoft\Command Processor\Autorun (make it if it doesn't exist), and point that towards a .bat. This means you can very easily configure ANY variable without actually making any changes that aren't very easy to reverse. Make sure to add an @ECHO OFF so it doesn't tell you what you're doing every time you start a prompt :) – Phoshi – 2009-10-14T17:29:11.287

1Well, it does what it should, but it silently chops off all other arguments to ls – aviraldg – 2009-10-14T17:39:31.797

aaaand this is why I use a python script. Append a $* (means "all arguments", like %* in a batch file), and sorry for missing it out! – Phoshi – 2009-10-14T18:16:07.340

1

Instead of typing ls --color, you could define a bash alias:

alias ls='ls --color'

This would produce ls --color each time you write ls.

Mike

Posted 2009-10-14T16:24:29.297

Reputation: 11

Says alias is not recognized as an internal or external command,.. you know the rest. – Qwerty – 2016-06-14T13:40:41.487