The Trifecta for Linux CLI

4 minute read

Running Linux on the desktop is fulfilling, but it can be tedious at times when you need to work on the command line. Linux distributions come with Bash as the shell by default and because of this most people never investigate alternative solutions. Not that Bash isn’t powerful, but you could easily set up an intuitive system as your desktop’s daily driver.

If you want a modern shell that integrates nicely with your workflow then you should consider Z Shell (Zsh). More specifically, the trifecta combination of Zsh, Oh My Zsh, and fzf.

What makes Oh My Zsh worth your time to install? The short answer is the plugins. The first plugin you should install is fzf, which is why I have it is included in my trifecta. It’s a good starting point to highlight the power of Zsh. It can be hard for Linux veterans who haven’t experienced Oh My Zsh to comprehend how useful their traditionally boring shell can be.

Z Shell (Zsh)

Zsh is an improved version of Bash that includes some of the best features from Bash as well as KornShell, and tcsh, two shells that might not get a lot of love, but are remarkable in their own right. Zsh can be used as a drop-in replacement for Bash, so there’s no need to modify existing Bash scripts when switching to Zsh. Even bash -c works while using Zsh as your shell.

Oh My Zsh

Oh My Zsh framework is the star of the show, which becomes evident when you search for z shell and the Oh My Zsh website has a higher position. It’s the free and open-source framework that helps you manage your Zsh configurations, so you won’t have to spend time tinkering (though you have this option) with files to get the full benefit of switching to Zsh.

Fzf (Fuzzy finder)

Fzf might be one of the most beneficial CLI tools for productivity in a while. Remembering specific file names, locations, or even file types can be a pain, but this small piece of software will change your entire way of searching and opening arbitrary files. It’s the closest thing to a futuristic CLI “assistant” that exists.

With Fuzzy search alone, you’ll begin to prefer using the command line over messing with a GUI in many instances. The speed and precision afforded here is similar to why Vim or Emacs have cult followings. The removal of the mouse for most input can drastically increase your speed. Your hands are already at the keyboard, so why move one hand to fiddle with a mouse when you don’t have to.

Searching for a file where you are not know the exact filename or location can be a hassle. But by executing the command find * -type f | fzf > selected, which you can add to an alias, you are prompted with an interactive, near real-time file search as you type. Search Prompt

Moving and accessing deep directories is tedious. You either must navigate to it in a file explorer or type out the full path , not to mention it’s case sensitive.

Normal Shell

[~]$ cd ~/Documents/investments/Properties/Illinois/Chicago/
[~/Documents/investments/Properties/Illinois/Chicago/]$ 

fzf powered

Instead, if you know the first character of each directory, which can sometimes be easier:

[~]$ cd ~/d/i/p/i/c
[~/Documents/investments/Properties/Illinois/Chicago/]$ 

Viola, you’re in the directory. Thanks to fzf for predicting where you want to go. Instead of your CLI needing explicit directions, it now aides you by making educated guesses based on several factors, including previously used locations (or commands).

These same general principles can be leveraged throughout your CLI endeavors. Searching for files, viewing logs.

Code Completion

Regularly typing commands that you use on a normal basis is tedious and time-consuming. Of course, you can traverse bash’s history by hitting the “Up” arrow repeatedly until you come across the command you’re looking for and may even need to modify. You could also use the relatively unknown “Ctrl+R” keyboard shortcut.

There’s a much better way; simply start typing the command you want, and when you get to a good point: Apt Update1

Then Hit “Up” arrow: Apt Update2 This time you’re greeted with the most likely command based upon previous commands you’ve entered. Again, we have a much smarter and more intuitive system. I can’t do the full feature set justice in one post so you should check out the zsh-completion page.

Wrappers

Wrappers are plugins that are essentially pre-configured aliases and functions for different CLI tools/scripts, but with the benefit that you don’t have to manually manage and update them when things change.

Since I work with Docker, I will typically use a command like:

[~]$ docker-compose build

With the docker plugin, I can type:

[~]$ dcb

Conclusion

I’ve just scratched the surface on what you can accomplish with Oh My Zsh. With that said, there are over 200 plugins you can look through. No doubt there is something for everyone.