Mastering Zsh on macOS: A Guide to Oh My Zsh, Plugins, Themes, and Productivity Hacks
Unlock the potential of your terminal with Zsh and Oh My Zsh — how to install and customize with plugins, themes, and aliases.
The Z shell (Zsh) is a Unix shell that can be used as an interactive login shell and as a command interpreter for shell scripting. Oh My Zsh is a framework built on top of zsh that is structured to allow it to have plugins and themes.
You can install zsh on Mac with Homebrew:
brew install zsh
To visit Oh My Zsh page:
To install, open your terminal and copy&paste the following:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
You can find superb plugins in this GitHub account:
Plugins — Manual Installation:
Navigate to plugins folder (~/.oh-my-zsh/custom/plugins) from your terminal:
cd ~/.oh-my-zsh/custom/plugins
You can now “git clone” the plugins you select among the GitHub projects such as:
git clone https://github.com/zsh-users/zsh-autosuggestions
To enable the plugin, you need to add it to the config file (~/.zshrc). Navigate back to the root and edit the file. I prefer to use “nano” for editing. It is a small editor for the terminal. You can install nano with Homebrew:
brew install nano
Let’s edit the config file:
nano ~/.zshrc
Find “plugins” section:
After edit:
Now, you have to start a new terminal session or run the following command (for the changes to take effect without restarting your terminal:
source ~/.zshrc
Let’s check (I typed the letter “p”):
Voilà!
Plugins — Installation with Homebrew
Let’s install “zsh-autosuggestions”:
brew install zsh-autosuggestions
Do what it says under “Caveats” section; edit your “~/.zshrc” file and add the following to the end of the file.
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
After that, restart your terminal or run the “source ~/.zshrc” command.
Let’s now install “Fast Syntax Highlighting (F-Sy-H)”:
brew install zsh-fast-syntax-highlighting
Do not forget to perform the instructions the “Caveats” section; edit your “~/.zshrc” file and add the following to the end of the file.
source /opt/homebrew/opt/zsh-fast-syntax-highlighting/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
It is not written there but restart your terminal or run the “source ~/.zshrc” command.
Let’s check (I typed the letter “p”):
To accept the auto-suggested command, press the → key (forward-char widget).
Voilà!
Default Themes
All the current themes can be found in the “themes” directory:
open ~/.oh-my-zsh/themes
In order to enable a theme, set ZSH_THEME to the name of the theme in your “~/.zshrc” file. The default one is “robbyrussell”. If you do not want any theme enabled, just set its value blank.
Aliases
You can set personal aliases by creating a file with “.zsh” extension and save it under “~/.oh-my-zsh/custom” folder.
These can also override those already provided; for the full active list, run the “alias” command:
Now, I will navigate to “custom” folder:
open ~/.oh-my-zsh/custom
There you will find a sample “zsh” file named “example.zsh”:
I will create a file named “update-stuff.zsh”:
nano ~/.oh-my-zsh/custom/update-stuff.zsh
This will be the content of my file:
alias update-stuff='echo "Updating Homebrew..." && brew update && brew upgrade && brew upgrade --cask --greedy && brew cleanup && echo "Updating App Store apps..." && mas upgrade && echo "Update finished!"'
“mas” (included in the command above) is a command-line interface for the Mac App Store. You can install it with Homebrew:
brew install mas
After saving the file, run the following command (for the changes to take effect without restarting your terminal:
source ~/.zshrc
Now you can run “update-stuff” command from your terminal (as I type, it is already being auto-suggested):
Happy Coding!