Sunday 8 April 2012

Changing the colour of directory listings in FreeBSD & ZSH

By default when you use ls to list the contents of a directory you only get the output below.



I've made this a little more pretty by adding the following to my ~/.zshrc file

alias ls="ls -GF"

The output now is easier to read but it has an issue where all the directories are using blue. This isn't very readable on a black background.




I've lived with this for long time. Today I discovered a easy way to fix only the colours of the directories.

The default colour scheme ls uses to display the contents of a folder is "exfxcxdxbxegedabagacad". This is decoded as follows:

The color designators are:

      a     black
      b     red
      c     green
      d     brown
      e     blue
      f     magenta
      g     cyan
      h     light grey
      A     bold black, usually shows up as dark grey
      B     bold red
      C     bold green
      D     bold brown, usually shows up as yellow
      E     bold blue
      F     bold magenta
      G     bold cyan
      H     bold light grey; looks like bright white
      x     default foreground or background

Note that the above are standard ANSI colors.  The actual display may differ depending on the color capabilities of the terminal in use.

The order of the attributes are:

      1.   directory
      2.   symbolic link
      3.   socket
      4.   pipe
      5.   executable
      6.   block special
      7.   character special
      8.   executable with setuid bit set
      9.   executable with setgid bit set
      10.  directory writable to others, with sticky bit
      11.  directory writable to others, without sticky bit


You can change the default to "hxfxcxdxbxegedabagacad" (ie light grey for the directories, everything else the same) by adding the following to your ~/.zshrc:

LSCOLORS="hxfxcxdxbxegedabagacad"
export LSCOLORS

The output from ls is now far more readable.



No comments:

Post a Comment