If you’re looking to supercharge your terminal, Zsh (Z shell) is one of the best tools you can use. Combined with Oh My Zsh, Powerlevel10k, and a suite of plugins, you can transform your terminal into a highly efficient, visually appealing, and powerful environment. In this guide, we’ll walk you through configuring and using everything defined in the sample .zshrc file.
The file is written for Mac OS, some updates might be needed to support Linux OS
1. Installing the Basics
Install Zsh
Zsh is the default shell on macOS, but if it’s not installed, you can add it:
brew install zsh
Install Oh My Zsh
Oh My Zsh is a framework that makes managing Zsh configurations, themes, and plugins easy:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Install Powerlevel10k Theme
Powerlevel10k is a fast and highly customizable Zsh theme:
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
Set the theme in your .zshrc file:
ZSH_THEME="powerlevel10k/powerlevel10k"
After setting up, run:
p10k configure
This will help you customize the prompt with useful features like Git status, Python environments, and more.
2. Powerlevel10k Instant Prompt
The instant prompt ensures your terminal loads quickly by displaying the prompt even before .zshrc finishes loading. Here’s the relevant configuration:
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
- The
quiet option suppresses warnings about instant prompt issues.
Why Use It?
3. Plugins for Productivity
Oh My Zsh supports plugins that extend the functionality of your terminal. Here are the plugins we’ve defined and how to use them:
Plugin Configuration in .zshrc:
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
history
vscode
kubectl
)
What Each Plugin Does:
git: Adds helpful Git aliases and shortcuts:
gst for git status
gco for git checkout
zsh-autosuggestions: Suggests commands based on your history as you type.
- Use the
→ key to accept suggestions.
zsh-syntax-highlighting: Highlights commands and flags to improve readability and catch errors.
history: Enhances your command history management.
history shows past commands.
vscode: Provides shortcuts for opening files and projects in Visual Studio Code.
- Example:
code . opens the current directory in VS Code.
kubectl: Autocompletes and adds shortcuts for Kubernetes CLI commands.
- Example:
k get pods instead of kubectl get pods.
4. Environment Variables
Environment variables are crucial for customizing your development environment. Here’s how they’re configured:
Java Configuration:
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
NVM (Node Version Manager):
if [ -d "$HOME/.nvm" ]; then
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
fi
5. Aliases for Efficiency
Aliases are shortcuts for commonly used commands. Here’s how they’re loaded and used:
Loading Aliases:
if [ -d "$HOME/.alias" ] && [ "$(ls -A $HOME/.alias)" ]; then
for file in $HOME/.alias/*.sh; do
[ -f "$file" ] && . "$file"
done
fi
Examples of Aliases:
alias ll="ls -la"
alias gs="git status"
alias gp="git pull"
alias vim="nvim"
6. Additional Integrations
iTerm2 Integration:
if [ -e "$HOME/.iterm2_shell_integration.zsh" ]; then
source "$HOME/.iterm2_shell_integration.zsh"
fi
- What It Does: Enhances iTerm2 with features like split panes and session restoration.
Backups and Reloading:
alias backup-zshrc="cp ~/.zshrc ~/.zshrc.backup && echo 'Backup created at ~/.zshrc.backup'"
alias update-zsh="source ~/.zshrc && echo 'Reloaded .zshrc settings'"
7. Customizing Powerlevel10k
You can customize Powerlevel10k using the following command:
p10k configure
This wizard allows you to set:
Prompt layout (e.g., minimal, classic).
Colors, icons, and separators.
Display options (e.g., Git branch, time, battery level).
If you want to tweak configurations manually, edit ~/.p10k.zsh.
8. Final Touches
Clean Up Unused .env and .alias Files
Ensure there are no unnecessary files in ~/.env and ~/.alias. Only include variables and aliases you actively use.
Restart Zsh
After making changes, reload your shell:
source ~/.zshrc
By following these steps, you’ll have a Zsh terminal that’s not only beautiful but also optimized for productivity.
Complete .zshrc file is added for reference
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k"
ENABLE_CORRECTION="true"
COMPLETION_WAITING_DOTS="true"
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
history
vscode
kubectl
)
source $ZSH/oh-my-zsh.sh
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
bindkey -v
if [ -d "$HOME/.env" ] && [ "$(ls -A $HOME/.env)" ]; then
for file in $HOME/.env/*.env; do
[ -f "$file" ] && . "$file"
done
fi
if [ -d "$HOME/.alias" ] && [ "$(ls -A $HOME/.alias)" ]; then
for file in $HOME/.alias/*.sh; do
[ -f "$file" ] && . "$file"
done
fi
export PATH="$PATH"
if [ -d "$HOME/.nvm" ]; then
export NVM_DIR="$HOME/.nvm"
if [ -s "$NVM_DIR/nvm.sh" ]; then
source "$NVM_DIR/nvm.sh"
fi
fi
if [ -e "$HOME/.iterm2_shell_integration.zsh" ]; then
source "$HOME/.iterm2_shell_integration.zsh"
fi
alias backup-zshrc="cp ~/.zshrc ~/.zshrc.backup && echo 'Backup created at ~/.zshrc.backup'"
alias update-zsh="source ~/.zshrc && echo 'Reloaded .zshrc settings'"
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh