Why use ZSH?

Why use ZSH?

We are going go through the process of setting up ZSH and Oh My Zsh on Mac and WSL2’s Ubuntu 20.04

ZSH is a replacement shell for Linux and Mac terminals. ZSH can do everything that BASH can do plus more. In fact the latest version of MacOS (Big Sur) actually defaults to the ZSH shell.

There are many features but the following are just four of my favorites.

  • Automatic cd: Just type the name of the directory relative to current folder or the full path
  • Recursive path expansion: For example “/u/lo/b” expands to “/usr/local/bin” when you hit the tab key
  • Plugins to auto complete common tools such as git, npm and loads more
  • Amazing history navigation: what this means, is that in addition to just pressing up for your most recent command, you can start typing a command and when you press the up key it’ll only show the history that starts with those characters

Oh-My-ZSH?

oh-my-zsh is a plugin for zsh that has lots of convenient features including loads of useful built-in command aliases (that can be found on this cheat sheet) but my favorite thing? Loads of themes to customize your terminal both included (see examples of the built-in themes here) as well as third-party themes.

Directions

  1. Install ZSH if necessary. First to check, run from a Mac/Ubuntu terminal, zsh --version, If you get a version number it is installed, Skip to the next major step.
  2. Install ZSH
    • WSL2 Ubuntu:
      1. Run from the ubuntu shell, entering your password when prompted sudo apt install zsh -y && chsh -s $(which zsh)
      2. Close and re-open the shell
      3. A tool will launch to config ZSH, press q to ‘Quit and do nothing’
      4. Update the zsh config file, ~/.zshrc for nvm by running:
    • MacOS prior to Version 11 (Big Sur)
      • directions to come at a later point in time, sorry
  3. Install prerequisite third party terminals so we can see the cool new fonts and better range of colors.
  4. Install oh-my-zsh
     # file: "install-oh-my-zsh.sh"
     sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    

    1.

  5. Check if nvm still works, by running nvm --version run the following command if you get an error:
     # file: "fix nvm.sh"
     echo '\n# nvm setup from .bashrc\nexport NVM_DIR="$HOME/.nvm"\n[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm' >> .zshrc
    
  6. Optional but suggested, pick a theme! I an NOT a fan of the default theme. There are 2 main ways to get a theme, choose an included one, or download an external theme. I recommend trying one of the included ones, option 1, before trying my preferred external theme, option 2.
    1. Using an included theme
      1. Visit the theme page, and find a theme you like. Note that a few have instructions beneath the image.
      2. Open the zsh config file in VS Code: code ~/.zshrc
      3. Find the line that starts with ZSH_THEME and change the theme name to the one you’ve selected
    2. Use an external theme most can be on this list of external themes
      • These require additional configuration, I will not be explaining how to set up any of them them.
      • The theme I used and is source of the video below, is powerlevel10k It is very configurable and geeky in my opinion.

Aaron Young © 2020. All rights reserved.