From my Notebook >

Use a nicely colored ls directory display in iTerm2 for OS X

It’s the 21st century, and it feels kind of ridiculous not to have pretty colors showing the different types of files in a folder when you use the “ls” command.

You’re already using iTerm2 (right?) so let’s customize the situation a bit. First we’ll make ls use colors, then we’ll add a new color scheme.

Customize the ‘ls’ command to use colors

Open the .bashrc file in your home directory. If you don’t have one, make one.

I used the command vim ~/.bashrc to do this. Then in Vim I pressed GA (shift+G shift+A) to go to the end of the last line and start editing. I pressed the enter key and added the following line at the end of my .bashrc file:

alias ls="ls -G"

Now, that ‘G’ has something to do with using a “long listing format.” I’m not sure why that makes colors show up when you use the ls command, so let me know if you know.

My actual .bashrc line is alias ls="ls -GFlash" because this group of options gets me more readable information like “1.4M” for file sizes, a slash at the end of a folder name, etc.

When you’re done editing, save and quit. In Vim I pressed “Esc” then typed :wq (colon w q) to Write the file (save) and Quit.

Now, back at our command prompt, let’s use the source command to basically execute the commands in our .bashrc file:

source ~/.bashrc

(Thanks to Mariz Melo for the info about this.)

Get a nicer color scheme for iTerm

In iTerm2, go to iTerm > Preferences > Profiles

Select click Load Presets... and then click Import... at the bottom of the menu.

Now go get some nice color schemes. GitHub user Baskerville has a nice set. Download them here.

Unzip the color scheme file. Using iTerm’s Import command, above, select the group of files you just unzipped and import them.

Now the list of available colors in the Load Presets... menu should be updated. I chose “thayer”. I think it’s pretty.

Even more fun stuff

  • I might try Oh My Zsh next. Looks convenient.
  • I installed the sl script (download link) by copying it to /usr/bin/ and making it executable. It’s a pretty cool alternative to ls! The sl script groups files by type (under headings even!) and can point out “interesting” files and folders.