Topic: Work Tools Revamp - zsh and oh-my-zsh

Topic type:

Second installment in a series on sprucing up my text editor, shell, rubies, etc. This covers modernizing my shell experience by switching to zsh from bash and taking advantage of oh-my-zsh.

Background

Over the last few years zsh seems to have become the shell of choice in the Ruby and Ruby on Rails communities. After usng bash for so long, I was hesitant to switch, but I've finally been won over.

Seeing oh-my-zsh built on top of zsh made me realize that zsh is demonstrably more productive than bash because of the values of the community of developers that use it. It, like homebrew, rbenv, pry, etc. pushes for continual improvement rather than simply settling for what everyone else has used in the past.

I use emacs/Aquamacs as my text editor and primarily use shell-mode within my text editor session rather than Mac OS X's Terminal.app, so the set up up for zsh and oh-my-zsh was a bit different than what you see written already around the web.

Install and Set up zsh

First, get the latest zsh via homebrew (this can be skipped if you are happy using Mac Os X's /bin/zsh instead, adjust steps below accordingly  if so):

The last command works around an issue in Mac OS X, apparently.

Another optional step is to set your OS X machine's default shell to the latest zsh. If you are using the homebrew version of zsh (aka /usr/local/bin/zsh) this takes some extra fiddling. You may decide it's not worth the trouble:

Next our SHELL variable needs to be updated. I'm currently on Aquamacs nightlies to get emacs 24 support and using a branch of my aquamacs-emacs-starter-kit to do this, but here's how it is done (stick this in your .emacs or some other place in your load path):

If you use rbenv, you'll also need to adjust your zsh start up to pull in rbenv initialization (from https://coderwall.com/p/0o64yq, there is a oh-my-zsh plugin for rbenv that will do this, but currently buggy, switch to using plugin instead when that issue is closed). Here's what you'll need in ~/.zshrc or the like:

We'll later stick this in ~/.zshenv and then source it in via oh-my-zsh's version of ~/.zshrc.

Install and set up oh-my-zsh

That's actually brings us to oh-my-zsh. Take a look at the Railscast for background. Follow the Setup directions in the oh-my-zsh README.

Next you'll want to customize the ~/.zshrc file provided by oh-my-zsh to add the plugins you want, to pull in the previously mentioned ~/.zshenv for rbenv initialization (I do this instead of setting PATH in ~/.zshrc directly as oh-my-zsh recommends), and pull any backwards compatible set you want in something like ~/.profle:

# here's what I have for my plugins

and then at then at the end of the file...

I have my EDITOR set up in my ~/.profile which is why I source it.

You may have noticed that I use the github plugin. You'll need to do a gem install github if you haven't already to make use of it.

Now you are ready to use zsh and oh-my-zsh from emacs/Aquamacs and/or the Terminal.app. Enjoy!

Postscript

For the fellow Aquamacs people, you no longer need to explicitly set your PATH anymore once you make this switch. See the commit here for details.

Discuss This Topic

There are 1 comments in this discussion.

Read and join this discussion

join this discussion