Tuesday, September 27, 2011

OSX Terminal Colors for LS command

The terminal in OSX has very basic theming. You can change the background and foreground colors, the font face, etc. Coming from a gnome desktop, you may find it annoying that you can't change the colors of directories, links, and executables when typing the ls command.

To customize these settings, just fire up vim and create a .bash_profile in your home directory:

vim ~/.bash_profile

Then you can add the following to it:

export CLICOLOR=1
export LSCOLORS=exfxcxdxbxegedabagacad

The first line tells the terminal to use ANSI color sequences to distinguish file types. The second line is where all the magic happens.

Each pair of letters represents an individual foreground/background setting for a particular filetype. The pairs are defined as follows:

  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

The foreground and background colors can be one of the following:

  1. a   black
  2. b   red
  3. c   green
  4. d   brown
  5. e   blue
  6. f   magenta
  7. g   cyan
  8. h   light grey
  9. A   bold black, usually shows up as dark grey
  10. B   bold red
  11. C   bold green
  12. D   bold brown, usually shows up as yellow
  13. E   bold blue
  14. F   bold magenta
  15. G   bold cyan
  16. H   bold light grey; looks like bright white
  17. x   default foreground or background

As a quick example, let's make our directories and executable files easy to find:

export LSCOLORS=Gxgxxxxxcxxxxxxxxx

And this is the result:

No comments:

Post a Comment