CODEX

macOS transition from Bash to Zsh

Remo Hoeppli
Feb 1 · 6 min read
Customized Zsh shell

TL;DR

This blog post is about my findings from my personal transition from Bash to Zsh and describes how I got auto-completion for some small tools such as SSH config files and Git to work correctly and how I gave my new Zsh the look and feel of a modern shell using starship cross-shell prompt.

End of an era

Every macOS user that uses the Terminal on a regular basis might at some point have come across the message that introduced the end of the Bash era when upgrading from macOS Mojave to Catalina.

The bash deprecation message

My first attempt to work around this message was by simply ignoring it. After a while, it began to bother me, and I found another quick but efficient solution by silencing the deprecation message by adding the following command to my ~/.bash_profile file:

This simple move was nothing more than burying my head in the sand, pretending that there is no transition to do. Anyway, it worked pretty well for almost one year. Then over Christmas when deciding to upgrade to macOS Big Sur, I thought that it might be the right time now to definitely say goodbye to my beloved Bash. That was when I removed the command above from the ~/.bash_profile file and opened the pandora’s box with these cryptic looking letters that changed my shell to Zsh:

Can it really be that different?

To make it short: “Yes it can!” At least if you are used to a certain shell behavior and just want your shell to work as you expect it to do. What was going to be meant a thing of minutes ended in a whole day searching for solutions to small but yet impactful problems.

Make it fancy with Starship

On Bash I was an enthusiastic user of Powerline (which was btw also a struggle to get it working the right way, you can find my blog post on how to configure Powerline on Bash here) and I knew that by using oh-my-zsh it would be very easy to install Powerline on Zsh. This would have been an option since I didn’t want to stick with the ugly plain Zsh shell. On the other hand, I wanted something more future proof that really feels like you are working with a modern shell. So, I choose the starship cross-shell prompt since I wanted to try it in action for a pretty long time now.

Installing starship using brew is pretty easy:

Installing starship using brew

To activate it we need to add one more line (two with the comment) to the ~/.zshrc file.

Configuring starship in your ~/.zshrc file

This is basically enough to make it work. But since starship is a modern command line prompt using emoticons (yes, emoticons!), we also need to install a so-called “Nerd”-font which can be downloaded here. I got myself DejaVuSansMono since I found it very pleasant to work with. After downloading and installing the font it needs to be set within the preferences setting of your Terminal application:

Setting the font in the Terminal preferences

For further customizing I took a predefined Terminal color scheme provided by lysyi3m. To do so I cloned the repository, double-clicked on the alucard theme, and set it as default.

Cloning Git repo with Terminal themes by lysyi3m

The final result does look like this:

Modern looking shell with git repository information

Zsh Autocompletion

When first using Git in Zsh, I soon realized that the autocompletion did somehow not really work as expected. Again, I could have gone the way to use oh-my-zsh with its autocompletion which I personally didn’t find very convenient. So, I stuck with the brew zsh-completions package and the built-in Git auto-completion (for which to work correctly, you need to install a recent version of git using brew):

To make the zsh-completions work you need to add the following commands to your ~/.zshrc file.

When I first installed this, I realized a bug in the Git auto-completion when using it on a git checkout command to check out a remote branch for the first time. By the time of writing anyhow, this bug should have already been fixed, as I could not replicate it.

SSH Config File

Everybody that has used SSH and SSH config files on Bash in Linux knows how convenient and fast a good auto-completion can be. When I migrated to Zsh from Bash on macOS I was really annoyed by how the autocompletion for SSH worked (or not)! Luckily, I found an easy fix to get Tab autocompletion to work as I knew it from Linux. The solution was provided by Gilles ‘SO- stop being evil’ on serverfault.com and helped me quite a lot. Thanks, Gilles! It was nothing more but add this to your ~/.zshrc file.

Visual Studio Code

For me as a software developer, every time I mess around with my Terminal I need to check Visual Studio Code and its built-in Terminal to ensure I didn’t mess it up. Adding the following two lines to my settings.json in Visual Studio Code pretty much brought me the same Zsh experience I was already enjoying in the Terminal Application:

Last Words

Even though my transition from Bash to Zsh wasn’t a no-brainer, I finally feel satisfied with the result and with the knowledge that I am on the latest shell on macOS. The tweaks described above needed quite some time and I hope I can make your life easier with this blog post. Let me know if you have problems with any of the steps.

About the author

Remo Höppli is Co-Founder and Software Engineer at Earlybyte.

Earlybyte is an IT consultancy firm specialized in developing new digital solutions for companies around the world from digitalization to IoT solutions, close to the client and its business embracing agility.

Follow me on Twitter to get informed on new blog posts.

References

CodeX

Everything connected with Tech & Code

Remo Hoeppli

Written by

Remo Höppli is co-founder and software engineer at Earlybyte. He is a technology enthusiast and minimalism advocate striving for simplicity and efficiency.

CodeX

CodeX

Everything connected with Tech & Code

Remo Hoeppli

Written by

Remo Höppli is co-founder and software engineer at Earlybyte. He is a technology enthusiast and minimalism advocate striving for simplicity and efficiency.

CodeX

CodeX

Everything connected with Tech & Code

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store