3 years ago, I wrote a post about zsh, and how to switch bash to zsh on a Mac. I've been applauding zsh for some years now, and I keep loving it. Whenever I meet a developer using a terminal, and running a plain, standard bash, I would start rambling about the goodies of zsh. Just ask Claus Witt.
What is zsh ?
Zsh is basically a command-line interpreter, like bash etc. (zsh.org defines it as "a shell designed for interactive use, although it is also a powerful scripting language").
Now, a lot of users out there, may not be best buddies with shells, terminals, ssh etc. If you prefer clicking large buttons, using wizards, not learning command line commands for Mac or Linux/Unix, you may want to go checkout something else right now.
But for most developers in the Unix-based world (including those developing on Mac), being able to use a shell quickly and efficiently will save you time. Also, it allows for automation of your processes, making you do more, with less work.
Why use zsh ?
To begin with, it’s not even a big deal switching or trying zsh out. If you are currently using bash, you’ll feel right at home. Zsh uses a lot of the same shortcuts, has support for most of the features bash uses, and this means the only thing you’ll actually notice, is how the extra features just make things easier. Some of the key features for zsh are:
- Nice autocompletion for commands, aliases etc. Zsh allows you to tab through completions if there are multiple possibilities, showing possible completions in a nice grid, browsable even by arrow keys, to make it simple and fast to find exactly the completion you want.
- Autocompletion for remote files. If you are using scp to transfer a file to a remote server, zsh will figure out what you are doing, so if you try to autocomplete while typing the remote part, it will try to connect via ssh and actually perform autocompletion on the remote side.
- Functions in addition to aliases. It’s possible to create entire routines as zsh functions with arguments, allowing for complex functionality for running multiple commands in succession easily.
- Share history across sessions. When running multiple instances of zsh at the same time, the instances are able to share a common history, rather than being limited to only each its own. One of the most frustrating things to a bash user is typing in a long command, then searching for it again the next day via Ctrl+r, only to find it nowhere in the history.
- Searching through history. Remember that scp command you used 2 hours ago, and need again ? Reverse searching will locate it for you!
- Saving repetitive work using aliases and plugins. I'll get back to that in a dedicated oh-my-zsh post.
A lot of the features I mention here, are also available on bash mind you, in my world they just require less work setting up in zsh :)
Okay, you got me! How do I set it up ?
Well, it's really simple.
chsh will allow you to do it on most systems, as zsh is bundled with a lot of Mac and Linux distros. And if it's not on yours, you probably know how to use
apt to do so ;)
Anyway, the command needed to change shell on a Mac, is like this (Your location of zsh may vary):
chsh -s /bin/zsh
Where do I go from here ?
I'm going to post my personal ´.zshrc´ configuration on my repos soon. Until then, go checkout these resources to learn more!
zsh.org - The official resource on zsh
oh-my-zsh - The addon I use for setting up most features. Allows for theming, and has a bunch of plugins for git autocompletion, build shortcuts etc.