Categories
Uncategorized

zsh globbing

I love using zsh—it’s full of completely insane features that you wouldn’t even think of using. Until you come across a situation and think: That’s exactly what I need!

Today’s example is recursive globbing. How to pick out all the non-image files in the current directory? I needed to run docs2unix over them. You could come up with some evil find command, but in zsh it looks like this:

  % dos2unix **/*~*.(gif|png|jpg)(.)
  1. **/* picks out all files and directories, recursively.
  2. ~*.(gif|png|jpg) excludes images from that list.
  3. (.) ensures that only files and not directories are chosen.

Easy, peasy. :-)

Update: Even better, case insensitive globbing!

  % dos2unix (#i)**/*~*.(gif|png|jpg)(.)