How to Supercharge Your Zsh Customization with Oh My Zsh [Themes & Completion]
In the last article, you mastered how to install and basically configure Zsh. While Zsh in its standard state has convenient features that surpass Bash, its true potential is still dormant. The magic tool that will draw out 120% of Zsh's power and elevate your command-line experience from "comfortable" to "ultra-comfortable" is Oh My Zsh.
"Oh My Zsh" is a framework beloved by developers worldwide that makes managing Zsh's appearance (themes) and functionality (plugins) dramatically easier. You can install useful extensions created by volunteers in minutes, without having to write complex configuration lines one by one.
In this article, we'll walk through the specific steps from installing Oh My Zsh, to applying "themes" that will make your terminal dramatically cooler, to installing "plugins" that will supercharge your work efficiency by enhancing features like input completion. Let's start building your own ultimate terminal!
1. Installing Oh My Zsh
Installing Oh My Zsh is surprisingly simple. You just need to open your terminal, and copy and paste the single line of command below. However, Oh My Zsh uses git to manage its own updates and plugins, so you need to have Git installed beforehand.
The following command using curl is generally recommended.
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
When you run the command, the installer will start, and several processes will be performed automatically. When it's complete, the appearance of your terminal should have changed slightly. This is because Oh My Zsh has created a new configuration file for you, ~/.zshrc (your existing file is backed up), and applied the default theme.
2. Customizing the Look with Themes
One of the greatest pleasures of Oh My Zsh is its rich selection of "themes." By changing the theme, you can completely change the look of your prompt (the line where you type commands).
The configuration is done by editing the ~/.zshrc file in your home directory. Open the file and find the variable called ZSH_THEME.
# Contents of the .zshrc file (excerpt)
ZSH_THEME="robbyrussell"
By default, the theme is set to robbyrussell. Let's change this to a theme that's very popular with developers, agnoster.
# Edit this line in your .zshrc file
ZSH_THEME="agnoster"
After saving the file, run the following command or restart your terminal to apply the settings.
source ~/.zshrc
[IMPORTANT]: Some themes, like agnoster, require special fonts (Powerline fonts or Nerd Fonts) to display symbols like Git branch icons. If you see garbled characters, you will need to install and specify one of these fonts (e.g., `MesloLGS NF`) in your terminal's settings.
3. Extending Zsh's Functionality with Plugins
If themes are for customizing the look, plugins are for customizing the functionality. They can enhance input completion, add convenient shortcuts, and more. Enabling plugins is also done in the .zshrc file.
Find the line in the file that says plugins=(...). By default, the git plugin is enabled.
# Contents of the .zshrc file (excerpt)
plugins=(git)
You can add the names of the plugins you want to use inside these parentheses, separated by spaces.
Recommended Plugin 1: zsh-autosuggestions
This is a plugin that suggests the next command you might type in a light gray color, based on your command history. If the suggestion is what you want, you can just press the β (right arrow) key to confirm the input, significantly reducing the effort of typing. It's safe to say this is an essential plugin.
Since this isn't included by default, first install it into Oh My Zsh's custom plugin directory with the following command.
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Next, add zsh-autosuggestions to the plugins line in your .zshrc.
# Edit the .zshrc file
plugins=(git zsh-autosuggestions)
Recommended Plugin 2: zsh-syntax-highlighting
As you're typing a command, this plugin will color it green if the command is correct (exists in the system) and red if it's incorrect. This allows you to notice mistakes before you even run the command, dramatically reducing errors from typos.
Similarly, install it first.
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
And then add it to the plugins line in your .zshrc file.
# Edit the .zshrc file
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
After saving the file, run source ~/.zshrc or restart your terminal, and these powerful features will be available to you!
Conclusion
Great work! In this article, we've explained how to install the framework "Oh My Zsh" to transform Zsh into the ultimate shell, and took the first steps in customization with its core features, themes and plugins.
- Using Oh My Zsh makes complex Zsh configuration surprisingly easy.
- You can freely change the look of your terminal just by changing the
ZSH_THEMEin your.zshrcfile. - By adding plugin names to
plugins=(...), you can enable powerful feature extensions like input completion and syntax highlighting.
What we've introduced here is just a small fraction of the many themes and plugins available. The Oh My Zsh GitHub repository is a treasure trove of useful extensions you may not know about. We encourage you to explore it and cultivate your own "ultra-comfortable" terminal environment.
Now that you have your Zsh environment set up and you've discovered the joy of customization, you're probably eager to learn more about Zsh's own convenient commands and features. In the next article, we'll focus on explaining the useful commands and usage that Zsh originally has.
Learn Zsh's Basic Commands and Convenient Features (Completion, History, Globbing)