Setting ls to reasonable colors in cygwin
I often navigate folders in Windows explorer without using the mouse. This is quick, as you can jump to any file or folder by typing the first letters of the name and use backspace to go up one level. The speed is probably faster than what you achieve in a bash shell, where you complete names with tab.
In the Windows explorer, folders are listed first and have a yellow icon, files are just plain black-on-white. Using the bash shell in cygwin, I wanted to retain these mnemonic features.
Here is what goes into my .bashrc to achieve this:
alias ls='ls -A --color=auto --group-directories-first'
alias ll='ls -lh'
LS_COLORS='no=00:di=33;01:tw=33;01:ow=33;01'
LS_COLORS=$LS_COLORS':fi=00:ln=00:pi=00:so=00:bd=00:cd=00:or=00:mi=00:ex=00'
LS_COLORS=$LS_COLORS':*.sh=31:*.sh=31:*.exe=31:*.bat=31:*.com=31'
export LS_COLORS
A few words of explanation. It defines two aliases, one shadowing the ls command itself to 1) hide the . and .. folders in each output using the -A
option 2) use coloring on device which support it only with the --color=auto
3) have folders listed first with the --group-directories-first
. The second alias is really just a shortcut (using the first!) long listed dirs (with human readable file sizes).
The colors are basically bright-yellow (33;01) for all dirs, red (31) for executable files and default (00) for all other files and text. Note that it doesn’t really make sense to define a color for executable files in cygwin, as all existing files are executable per default.
Thanks for this tip. I’ve been fighting with dircolors in cygwin without any luck. By manually setting the LS_COLORS in my .bashrc file I was finally able to get the colors I’ve always wanted
Thank you for post! I have been problems with colors as Matt. I trying solve it a lot of time with DIR_COLORS and .bashrc. But your way is helped.