Zsh

Zsh

Oh My ZSH

If you follow this blog, you will know that I am a huge fan of the Maintainable podcast by Robby Russell. It contains lots of great information about working with Legacy Code and how to write code so that you avoid a lot of the issues with Legacy Code.

Robby is also the creator of Oh-My-Zsh. This comes out occassionally in the podcast. I’ve been doing a lot more with the Linux CLI lately, so I thought I would check it out. Oh My Zsh is a plugin manager for zshell. If you are using bash, think of zshell as an improved bash. All of your old bash commands work, but zshell adds a bunch of extra functionality on top.

Oh My Zsh is really quick and easy to install. There are instructions on the website. You just use curl to grab and run an install script. You may have to install zsh via your package manager first. The installer will ask you a few questions and you are up and running. You’ll immediately notice that your prompt has changed. By default, it is set to the Robby Russel theme.

here is what it looks like after you install Oh My Zsh

Oh My Zsh allows you to customize your prompt. There are a whole bunch of themes out there to choose from. If you want to experiment, set the theme in your .zshrc file to random and it will pick a different one each time you log back on or source your .zshrc file. It tells you which one it has picked. Find the one you like and then set it to that.

Oh My Zsh also has a plugin system. This allows you to add plugins with all kinds of useful functionality. Many just add some aliases for common commands. Several add a bunch of extra tab-completion functionality for common programs like docker or git.

PowerLevel10k

There is a great theme called Powerlevel10k. I highly recommend it. You have to install it, but it is easy to install. There are instructions on the site. Install Oh My Zsh first and then in the install section on the Powerlevel10k page, find the instructions for installing into Oh My Zsh. You basically clone the repository and then edit .zshrc to point to powerlevel10k as the theme.

powerlevel 10k will ask you some questions on install.

Once installed, restarting your shell, you will get prompted to setup powerlevel 10k. It will ask you several questions about how you want to set it up. There are a ton of options. The best solution is to just try a set of options and see how you like it. If you don’t like what you have chosen’ just type p10k configure to run the configuration wizard again.

Why?

It only takes about 10 minutes to set up Oh My Zsh and PowerLevel10k, but why bother? This combination offers many features that dramatically improve your productivity. Here are a few of my favorites.

  • Tab completion – One of the biggest reasons I think a lot of people avoid the CLI is not wanting to memorize a bunch of commands. I get it. Tab Completion can help with that. If just remember what a command starts with, type the first couple of letters and then hit tab. Now most shells do this already but this extends it. It shows all the options and allows you to quickly tab through them. It also lets you tab through subcommands as in git and docker. For example, type in git and a space and then hit tab and it lists all the possible git commands. Tab completion also works great for really long file names. It will also, automatically escape spaces in your filenames.
  • Change directories without typing cd. Just type in the name of the directory and hit enter. Ok this only saves you a tiny bit but it is nice.
  • Git info – This displays git information in the prompt. It can tell you how many files you have modified, added or untracked. It can tell you if you are ahead or behind of your remote branch and by how many commits. Very useful information.
  • Plugins – as I mentioned, there are a lot of plugins to expand tab completion and add useful aliases. One of my favorites is the ubuntu plugin. If you use Ubuntu you have probably typed sudo apt-get update && sudo apt-get upgrade way more times than you would like to count. If you add the ubuntu plugin, you can just type aguu
Here is the git info display.. Left to Right it is showing: I am in the folder Presentation. I am on the master branch. I am 1 commit ahead of my remote branch. I have modified 1 file and I have 2 untracked files.

What does this have to do with LabVIEW?

Good question. Most of us use LabVIEW so we don’t have to deal with text and the CLI, so why use this? Sometimes we are forced to use the CLI. In those cases, this is quick and easy to set up and makes using the CLI much easier.

Here are some cases, where the typical LV programmer may be forced to use the CLI

  • LabVIEW on Linux – LabVIEW does run on Linux. If you are running on Linux, then you are probably using the CLI a bit anyway.
  • RT Targets and Raspberry PI – if you are using RT targets running linux-rt or using a raspberry pi you are probably using the CLI a lot. I have installed this combo on a raspberry pi. I can’t vouch for any of the NI RT targets. I did check and didn’t see zsh in the opkg repo so maybe not possible or if it is you’d have to build it from source.
  • Managing Git from the CLI – if you are not using one of the fancy GUIs and managing Git from Git Bash, you could install WSL and try this.
    NOTE 1: even if you are using the fancy GUIs at some point you will probably have to use the CLI to clean something up when you make a mistake or get in some weird situation. It’s inevitable.
    NOTE 2: Be very careful with line endings. Before you start using WSL to manage git repositories on windows, lookup the git autocrlf function and make sure you understand the issues and have it set up correctly. If that seems like too much, stick to Git Bash.
  • Managing webservers and databases. Most webservers and databases run on Linux, so if as part of your project, you have to set those up or manage them, you will be using the CLI a lot.