Trying out zsh

Posted by phillip Sat, 14 Mar 2009 15:05:00 GMT

Have you consciously decided to use bash as your shell? I haven’t.
How often do you use the shell? For me, it’s one of the tools I use most.

So while bash does the job, why not find out if there’s something better? I’ve heard zsh mentioned a couple of times, and it seems to be smarter and more modern, while maintaining good compatibility with bash. So I’ll give it a try.

zsh Features selection

  • tab completion is programmable and depends on the command it is used with. examples:
    • cd<TAB> shows a list containing only directories
    • tab completion for options: `ls -<TAB>` shows a menu of available options, selectable with cursor
    • cd -<TAB> shows you a list of recently visited directory, select with cursor where to go. instead of pressing <TAB>, you could also have typed cd -2 to go to the 2nd last dir.
    • ssh<TAB> shows a list of all known hosts
    • kill<TAB> gives you a list of processes. another example: kill memca finds the correct pid and inserts it
  • cd-less directory switching (just type name of directory)
  • all shell windows share one history, i.e you can access a command from window A’s history in a new window B
  • can shorten the path shown in the prompt (“Resources/Styles/Marble $” instead of ”/Applications/ $”)
  • more powerful globbing. example: ‘ls \\*/\_helper.rb’ lists all *_helper.rb files in the current tree
  • temporary aliases for directories, using ~dirname: ~ $ work=`pwd` ~ $ cd / / $ cd ~work ~ $ pwd /Users/phillip
  • bash-compatibility
  • optional prompt at the right top side

How to start using it on OS X

  • OS X already ships with zsh installed. Type zsh to try it out! It’s pretty dumb without proper configuration, so …
  • get a .zshrc config file, like from here for example. That page is also a good intro and contains more links to useful resources.
  • to use zsh permanently (OS X Leopard): go to System Preferences > User, click the lock and authenticate, right-click on your user and select “Advanced Options”, then select /bin/zsh. Open a Terminal. To check, type echo $SHELL.
  • if your like using Ctrl-A/Ctrl-E/Ctrl-K … to go to the start or end of your command or delete to the end of the line, you’ll need to add ‘bindkey -e’ to the .zshrc file.

A tip, independent of zsh, if you create a .hushlogin file in your home dir, the shell will not display the “Last login …” blah on startup.

Posted in , | Tags , ,