The Joy of Z-Shell

Apr 17th, 2007No Comments

Late last week, I finally got the opportunity to upgrade my Cygwin to something modern.  Like, you know, within the past month instead of three years old.  But after the upgrade, bash was really giving me fits.  Horrid fits. Like not understanding blank lines in my scripts; completion was way off.  And other nasty bits. 

I’ve had looking at Z Shell for a while now and, since my bash was broken, I decided there was no better time like the present.  Among others, Ted Leung likes zsh and I think Ted is smart.  It was worth a try.

Converting my all-important bash aliases was easy — because zsh uses the same syntax.  Just a <code>source ~/.aliases</code> loaded my alias file.  Wonderful stuff.

You can do a ton of customization with zsh and you probably will want to. Luckily, on Cygwin, zsh notes if you have a <code>~/.zshrc</code> file and, if not, asks you to configure one.  It steps you through a few different commands (like tab completion, etc.) and then saves it.  Zsh uses “smart completion” similar to the bash-completion project.  Only it’s not a separate download.  In other words, if you have have new files you want to add to your svn project, type <code> svn add [tab]</code> and Zsh will display the files that aren’t in your project yet.  Neato.

Another neat completion trick — <code>./*.py[tab]</code> will display all the .py files in your directory.  Even if you have 100%.  You can also configure a menu of candidates during completion

There are other tricks besides completion:

  • hitting a ” and then a newline will give you a prompt that says “quote>”, so you know where you left off.  Something similar happens with a for statement, etc.
  • It has a bunch of built-in prompts.  Once you initialize <code>promptinit</code> type <code>prompt -l</code> to see a list, and the <code>prompt [name]</code> to choose that prompt.  I’m currently using “bart”.
  • Putting an = before a word does a which on that and then runs the command.  For example, <code> ls -l =python</code> is the same as <code>ls -l `which python`</code>. 

So I’m sold for now.  Z Shell is very cool indeed.

Powered by ScribeFire.

Leave a Reply

You must be logged in to post a comment.