Moving From Bash to ZSH and Prezto

Preamble

I spend pretty much my entire day inside the terminal. Upon first being introduced to CLI it seemed outdated and archaic. I eat those words pretty hard now. I’ve primarily used bash for everything becuase it’s the defacto solution on many platforms. It’s been versatile but it always felt like something was missing. I decided to do some researching to figure out if there was some kind of other alternative to try using. I came up with ZSH and prezto, I did look at oh-my-zsh as well but ultimately decided to go with prezto. Prezto seemed to align more with what I was trying to make my bash shell do but with much more functionality and less hassle. The best part is switching didn’t mean I had to revamp my old way of doing things on the command line. I use my .vim folder as a toolkit of sorts, I think I’ve mentioned this in other posts, by keeping it in git and then syncing it wherever I go. I kept my old bash config files and simply sourced them in my zshrc. This was the best part of trying out zsh, I didn’t have to do anything different, you can just start using zsh as if it were bash and you wouldn’t notice a difference. I quote most of the features found in this slideshow presentation because it’s what pretty much convinced me to make the switch.

Features:

1.) Autocomplete

ZSH has amazing autocomplete functionality. When you have multiple files it will give you a tabbed list that you can tab to instead of bash’s solution which is to just list the matching names. The autocomplete in zsh also worked for git and tmux with no additional configuration.

2.) Path Expansion

If you have an extremely long path you can simply type something like

$ cd /u/lo/b

and hit tab and you should see

$ cd /usr/local/bin

This is a pretty amazing feature. If there are multiple matches for any part of the path hitting tab will bring you to the conflict where you can resolve it with their autcomplete list functionality

3.) Path Replacement

Say we cd’ed into /usr/local/bin

$ cd /usr/local/bin

but we meant to go to /usr/local/share. Well we can use some awesome path replacement to fix our little mistake. After you change directories run this command:

cd bin share

This will take you to the /usr/local/share folder. This is nice for fixing mistakes but also if you are going through a bunch folders it can save you some keystrokes.

4.) Right Prompt

If you are using bash you know that the prompt is on the left side. Well in zsh you can also add to a prompt on the right side. This space is never used so it is kind of nice to have the option to put something there. I usually just put the time there so I can time stamp my commands

5.) Spell Correction

This one is a big one for me. Ever type a long command out only to realize that you typed ‘cim’ instead of ‘vim? No need to worry because zsh will notice that you typed an invalid command and try to match it to what it thinks you meant. This also applies to custom bindings that you create yourself in config files.

6.) Extended Globbing

Normal globbing can be used to find a bunch of files such as:

ls -l *.log

Now this is great when you are looking in one folder but when you have to search a bunch of them it can become tedious. In comes extended globbing to solve your needs.

ls -l **/*.log

This will recursively search through the next level of folders for anything that ends in ‘.log’. You can also extend this to additional levels:

ls -l **/**/.log

7.) Syntax Highlighting

If you are ever curious about whether or not a command in your $PATH zsh will just do some nice syntax highlighting to let you know. If a command is valid it will be green and invalid will be red. I found this a little annoying sometimes so changed it to just hightlight commands that were invalid

Conclusion

I hope that my post has given you some insight to why you might want to consider changing your shell to zsh. I still love bash but the additional features of zsh were enough to make me switch teams. You can try zsh out on your personal machine or boot up a Digital Ocean droplet but if you spend a considerable ammount of time on the command line you will probably enjoy the added functionality.