Migrating to ZSH

Episode #409 | 33 minutes | published on September 13, 2019 | Uses zsh-5.7.1
Subscribers Only
The new default shell in macOS Catalina is zsh. If you're like me and have been using Bash for years, this is probably a good time to make the switch. In this episode I will go over installing zsh, adding a little configuration as well as some of the features it has over bash. I'll also install oh-my-zsh and customize my prompt using Powerline fonts. Finally I'll import some well-used Bash aliases and functions that I've used for years.
In this episode there's a bit of a buzzing sound (perhaps due to a bad XLR cable). I cleaned up the audio quite a bit, but it's still audible in a few places.

Episode Links

Installing zsh

  • If you’re on Catalina, it’s already installed to /bin/zsh
  • If you’re on Mojave or earlier, or want the most recent version of zsh:
brew install zsh

You’ll also have to make sure that this shell is blessed to be a user’s shell. Do this by adding the path to the zsh binary to /etc/shells:

sudo vim /etc/shells

In my case I had to add /usr/local/bin/zsh to this file.

Then change the shell for your user account:/Users/ben/.zshrc

chsh -s /path/to/shell

zsh Features

Some of these have to be enabled before working, but this is a general overview of some of zsh's features.

  • Directory completion: cd D<tab>. Pressing tab multiple times will loop through the available matches. Press enter to select.
  • Path expansion: cd /us/lo/bi<tab> expands to /usr/local/bin automatically.
  • AutoCD: Desktop will cd into Desktop. .. will cd back up one level. I used to use a bash alias for this, but now it's builtin.
  • Right side prompts
  • Global aliases - apply aliases anywhere in a command
  • Suffix aliases - match on a suffix. Automatically open .txt files with a text editor, for instance.
  • which will show you aliases & functions in zsh. Super handy when you want to know what a command does, even if it's an alias.

Installing oh-my-zsh

This is a swiss-army knife of configuration. Only install this if you're comfortable and don't mind learning someone else's configuration.

Follow the instructions here to install & configure oh-my-zsh.

blog comments powered by Disqus