Shape of the problem, better colored ls output on Macs

February 10th, 2013  |  Published in etc  |  1 Comment

BBEdit tells me it found 439 occurrences of “img src” in 317 files in the Markdown archives for dot unplanned, so this is starting to feel kind of doable. 122 of those occurrences are flickr images, only 27 use the ancient Movable Type 3 “click the thumbnail to pop up a window with the full image inside” markup, and 142 are consistently organized WordPress uploads I can manage with a little find-foo and a BBEdit text factory.

Hey … here are some things I learned to do, figured out or got around to:

Better color ls in Mac:

You can do ls -G in a Mac right now, without MacPorts or Homebrew installed, and you’ll get BSD-style colored output, which is to say “not as good as GNU-style colored output.” Directories, symlinks, and executables will be colored. That’s o.k. But I remembered back in Linux times where I could get things colored down to the file type. That’s what I prefer. I did some things one might reasonably do expecting to get that GNU-style output back on my Mac, missing a few key steps and badly aggravating myself, then stumbled across a missing piece last week while trying to figure out better bash prompts. So here’s what to do:

  • Pick one of MacPorts or Homebrew. I do Homebrew, so the steps after this one should be read as vague guidance by MacPortists.
  • Install the GNU coreutils package: brew install coreutils
  • Download this gist and save it to ~/.dir_colors
  • Make sure your new ~/.dir_colors file has a line in it that starts with “TERM” and then matches the output of the command echo $TERM
  • Get this into your ~/.profile or ~/.bash_profile or whatever it is you do*:
  • source your ~/.profile or ~/.bash_profile
  • Try it out in a directory full of different kinds of things:

Better ls colors

Is it awesome for you? Hope so!

More informative ls

I also learned about a few more nice ls options while I was mucking around, and now I include these in my ls alias:

  • -F (classify): Which marks symlinks and directories with a @ and / respectively. Yes, they are also colored, but I like seeing the trailing / after a directory.
  • --group-directories-first, which does what it says on the tin.
  • -h, for “human readable output” when displaying file sizes. I finally, after years of just typing it out, realized I never use ls without, so I canonicalized it. I eagerly await the first horrific misunderstanding that is going to cause me on some system that is not mine some day.

*Do I sort of hate the hall of mirrors that is .bashrc, .bash_profile, and .profile? Boy, I sure do. Especially in the age of things like rbenv/rvm and whatever else quietly diddles what they think your shell’s init file oughta be to make whatever blood magic they’re up to work correctly. I thought “just switch to zsh” would fix that, but then you start getting into bizarre “oh, that doesn’t work with zsh during install” situations that make you realize you’re losing all the time you thought you’d get back with obscure little shell workflow optimizations trying to figure out why suddenly which doesn’t work anymore.


  1. gl. says:

    February 10th, 2013 at 7:06 pm (#)

    “Do I sort of hate the hall of mirrors that is .bashrc, .bash_profile, and .profile?” amen. also, -F is one of my favorite flags forever.

Leave a Response

© Michael Hall, licensed under a Creative Commons Attribution-ShareAlike 3.0 United States license.