Experiences with zsh

I’ve been using zsh for a while now and although I am in no way a power user I’ve started to appreciate a number of its features.

First and foremost is the fantastic completion system. Pressing <TAB> at any point in entering a command line usually brings up the appropriate set of completions for that context. There’s a number of completion files published on the internet; I’ve added completions for lein, networksetup, port and vagrant to those provided by the default zsh installation. But as well as saving typing, the completion system functions as an instantly available help and aide-memoir. Forgotten the ls option to get a comma separated listing? Type ls - then hit <TAB>: you’re shown all the options together with a brief description.

ls.png

There are some nice features which help in navigation around directory trees. Hash a directory name

hash -d foo="/some/directory/path"

And then change to that directory by simply entering ~foo. There’s a nice extension to the venerable cd: adding -0 takes you to the previous directory, -1 the one before that etc. If you’re having trouble remembering when you were in a particular directory use completion: cd - then <TAB> will give you a list of directories and their index.

Want to change to a directory somewhere underneath your current directory that contains the file foo.bar?

**/foo.bar(:h)

The ** recursively searches for matches whilst the trailing (:h) modifier strips the trailing path element. For a list of applicable modifiers use the completion system again. As I have setopt autocd in my .zshrc simply entering a directory name changes to that directory.

The manuals are thorough if somewhat impenetrable. There’s also a very fine zsh guide which repays reading. If you’re trying to work out how the completion system works then this introduction is useful.