March 16, 2021 Improve Development Efficiency With Zsh and Oh My Zsh Zsh and Oh my Zsh add many efficiencies to the humble terminal, eliminating the excessive clicking around and increasing developer efficiency. Nikola Peevski With the vast increase in user interface applications for virtually everything, from simple text edits to source control management, our little terminal has been forgotten; we’re here to change that and answer questions like “What is Oh my Zsh?” Many developers today find the terminal a little bit intimidating in their everyday life due to the learning curve it imposes. I have to admit that I found myself in the same boat a couple of years ago. When I was using windows for my daily driver, I virtually hated using the mouse. I tried to avoid it as much as possible to the extent that I used the keyboard to navigate everywhere, right-clicking included (The shortcut is Shift+F10, by the way). I started looking into the popular thing back then: Powershell, of which I was not so fond. Fast forward a few months, I noticed a handy bash replacement called Zsh as I was setting up Linux. It intrigued me. Step by step, I got used to using the terminal with the help of some useful plugins and the OhMyZsh framework. What is Zsh and Oh My Zsh? Zsh (short of Z shell, I actually had to Google that) is a delicate and excellent bash replacement tool. It compiles many features from Bash itself, alongside other popular Unix shells like Korn shell, and adds on top of them. Complementary to that, adding Oh My Zsh introduces the possibility of tons of plugins, tweaks, and colors. Adding this combo to your workstation with a few nifty tweaks has the potential of eliminating the learning curve of using a terminal and even making you fall in love with having it as your daily driver. How to Set Up Zsh and Oh My Zsh I will not be going over the whole charade of installing Zsh and Oh my Zsh just because it’s a pretty straightforward process clearly explained in their docs. You might already have Zsh as your daily, depending on your operating system distribution. What I would recommend as an additional step is installing the Meslo Nerd Font. If you’re on Mac and keen on replacing your default terminal, I highly recommend installing iTerm. If you look into your home directory, you can find a hidden file called .zshrc, which holds your configuration and path variables. And, adding path variables to the bottom of the file is as easy as typing, for example: echo ‘export PATH=”/usr/local/opt/node@12/bin:$PATH”‘ >> ~/.zshrc Just out of the box using the robbyrussel theme, there are plenty of improvements like being able to go back in your command history (zsh has a zshhistory file as well): It comes in handy when you want to write a particular command without typing the whole thing, without the need to go through all of your history instead of the standard Bash shell. Additionally, you have fast directory access to your past 10 locations that you can view by typing “dirs -v” and accessed by merely typing the corresponding number: It’s a little magic at first, but if you remember that each entry gets removed and put on top of the history stack, it’s relatively straightforward to zoom around. These are my two most used vanilla features, apart from the whole terminal being a lot more usable with the color scheme on its own compared to the plain black and white bash one. (Which also supports color themes, by the way, but that’s a story for another time). Oh My Zsh and Zsh Theme My theme of choice is powerlevel10k which is an Oh My Zsh theme that adds a massive amount of much-needed information. Installation is straightforward and explained in the repository of the author. After running the installation and opening a new terminal, it should prompt you to go through the configuration process, after which you’ll notice your terminal looks a bit different: But there’s more to it. Suppose you navigate to a git repository folder. In that case, it clearly outlines incoming and outgoing commits and, when doing a merge, shows the amount of merge conflicting files, saving a few clicks around compared to a git interface, for example. In the GitHub ReadMe, you can find explanations of many more features. Oh My Zsh and Zsh Plugins Moving to plugins, as you can see, the list is quite long. There are many more plugins that are not even on the list. The possibilities are endless. I use only three plugins that are independent of each other, but together, they form a solid base. For each plugin installation, you need to clone the git repository under the home directory /.oh-my-zsh/custom/plugins/ resulting in the following: After you clone a repo, you need to edit the .zshrc configuration file, go under plugins and enable each plugin with their appropriate name: Going over the list, we first have zsh-syntax-highlighting. It will mark the command in green/light depending on whether it’s a valid command. It makes you get used to command syntax. It also helps you out if you have a typo when you’re in a pinch typing command after another one and suddenly you get a command not found. With the powerlevel10k theme, you’ll get a second notifier on the right, as if one was not enough. Second on the list, we have zsh-autosuggestions. This plugin makes autosuggestions based on your last similar command. Complemented with the syntax highlighting helps you out in both learning commands and fast typing something you previously typed without redundancy. And lastly, the stardust crusader in this trio is git-open. It’s probably my most used plugin and the inspiration behind this blog post. It’s a simple plugin like the rest, which opens the web link of the repo. That’s it. There’s a small twist to it, that if you’re on a branch, it will open the repo with the selected branch. It is saving quite a bit of navigating, clicking around, searching, etc. Zsh and Oh My Zsh Final Thoughts To sum up, Zsh and Oh my Zsh add many efficiencies, eliminating the excessive clicking around. With the addition of the plugins mentioned above, they do the job pretty well, even for people new to using the terminal. The beauty of it all is that everything is modular. If you don’t like a particular plugin, you can omit using it and use a different combo of plugins that complement each other. This whole setup works straight into the integrated terminals of IDEs, such as Visual Studio Code, IntelliJ, etc. Image source: Michał Parzuchowski on Unsplash Tags Agile Software ProcessDevelopmentWebCross Platform Share Share on Facebook Share on LinkedIn Share on Twitter Over-Engineering Learn the causes and costs of over-engineering your solution and how to avoid it from occurring in the first place. Download Share Share on Facebook Share on LinkedIn Share on Twitter Sign up for our monthly newsletter. Sign up for our monthly newsletter.