Zsh on OSX

It sounds strange to talk about a shell, when you are talking about OSX. It is not linux is it? But having come from linux, at least for me, many things are just faster from the shell. And combine an always running terminal with quicksilver and you are typing in the blink of an eye. And why zsh? Well, not all shells are created equally. One shell rules them all… Anyway, it has way more shortcuts and other goodies then any other shell.

Introduction

OSX has several shells installed. Still, for people who want to do more with their computer the shell is important enough to warrant some extra effort. Zsh is the most powerfull shell available today. With very little investment in time, many things can be made a lot easier in the long run, using zsh. My favorite is being able to use tab-completion on a foreign host when I am using ssh, but there are many others.

The latest version of zsh plus the templates on google-code
will make working on the command-line on OSX fast and very effective.

Installation

Zsh is already installed on recent versions on OSX (try which zsh, probably /usr/bin/zsh), but the devel version on fink or ports is much more up-to-date.

I am using mac-ports (mac-ports guide), but fink works along the same lines:

sudo port install zsh-devel +mp_completion +pcre +dec +examples

Additional zsh templates: zsh-templates-osx on google-code, can be installed using:


cd /Library
sudo svn co http://zsh-templates-osx.googlecode.com/svn/trunk/Library/init
cd /private
sudo svn co http://zsh-templates-osx.googlecode.com/svn/trunk/etc

To get quickly up-to-speed install the files from /private/etc to ~/.zshrc and ~/.zshenv. When you run the zsh shell for the first time (after copying these files in place) it will ask you to configure the shell and in a couple of minutes you have a really nice shell.

Note: To make your rc files look half decent, set them to Shell Script, if you are using textmate, using: ⌃⌥⇧S – 1, or from the menu at the bottom of the edit-window

Files to store personal configuration (but see ~/.zsh):

  • ~/.zsh/aliases.mine
  • ~/.zsh/functions.mine

Goodies

Command-line-completion

So what makes zsh actually better then, say bash with command-line completion? Well, for starters, the command-line-completion :-), bash has caught on but not yet overtaken zsh. Take for example the port command:

# port ⇥

On pressing ⇥(tab) zsh will show you all the secondary commands port takes, pressing tab ones again, it will activate activate, now you can use tab or the arrow-keys to navigate to the command you need.

Ssh

A lot of administration work is done using ssh. OSX can make working with ssh a lot faster as well. The google templates have some extra tools as well, that will make it easier to configure what users and hosts actually get completed using ⇥. Configuration can be done using user_setup or host_setup.

To avoid being asked for ssh passwords all the time, install a shared key on the server you want to administer (see
here). Now when you, for example, try to copy a a file, you can use command-line-completion just as you can on a local host.

Note: Use SSHKeychain as an ssh-agent (sudo port install SSHKeychain)

More later…

Links

Advertisements

1 Comment

Filed under osx

One response to “Zsh on OSX

  1. Just used you instructions to install my ZSH and I wrote a Portuguese article about that, thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s