Setting Up Zsh Terminal and Configuring It with Powerlevel10k
Switching to Zsh (Z shell) as your terminal shell can enhance your productivity with features like customization, themes, and plugins. Here's a detail
Step 1: Install Zsh
Check if Zsh is already installed:
zsh --versionInstall Zsh if it’s not installed:
MacOS (using Homebrew):
brew install zshUbuntu/Debian:
sudo apt install zsh -yFedora:
sudo dnf install zsh -y
Set Zsh as the default shell:
chsh -s $(which zsh)Restart your terminal to use Zsh.
Step 2: Install Oh My Zsh
Oh My Zsh is a framework for managing your Zsh configuration.
Install Oh My Zsh:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"Verify Installation: After installation, you’ll notice your terminal prompt changes, indicating Oh My Zsh is active.
Step 3: Install and Configure Powerlevel10k
Powerlevel10k is a popular theme for Zsh, offering a highly customizable and visually appealing prompt.
Install Powerlevel10k:
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10kSet Powerlevel10k as the Theme: Open your
.zshrcfile:nano ~/.zshrcUpdate the
ZSH_THEMEline:ZSH_THEME="powerlevel10k/powerlevel10k"Apply the Changes:
source ~/.zshrcRun Configuration Wizard: Customize the theme using:
p10k configure
Step 4: Install Zsh Plugins
Plugins enhance Zsh by adding helpful functionalities. Here are some essential plugins to install:
Install Plugins:
zsh-autosuggestions:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestionszsh-syntax-highlighting:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Enable Plugins in
.zshrc: Add these plugins to thepluginsarray:plugins=( git zsh-autosuggestions zsh-syntax-highlighting jsontools history dirhistory vscode docker kubectl terraform aws pip python npm )Apply Changes:
source ~/.zshrc
Step 5: Add Custom Paths and Environment Variables
Customize your .zshrc to include paths for tools and frameworks you frequently use:
# Java
export JAVA_HOME=`/usr/libexec/java_home -v 17`
# Flutter
export PATH="$HOME/development/flutter/bin:$PATH"
# Android SDK
export ANDROID_HOME="$HOME/Library/Android/sdk"
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"
# MySQL
export PATH="/usr/local/mysql-8.0.36-macos14-arm64/bin:$PATH"
# Node.js
export NODE_PATH=$(which node)
Step 6: iTerm2 Integration (Optional)
If you’re using iTerm2, enable shell integration for an enhanced experience:
curl -L https://iterm2.com/shell_integration/zsh -o ~/.iterm2_shell_integration.zsh
source ~/.iterm2_shell_integration.zsh
Step 7: Backup and Reload Configurations
Create shortcuts for backing up and reloading your .zshrc file:
# Backup .zshrc
alias backup-zshrc="cp ~/.zshrc ~/.zshrc.backup && echo 'Backup created at ~/.zshrc.backup'"
# Reload .zshrc
alias update-zsh="source ~/.zshrc && echo 'Reloaded .zshrc settings'"
Step 8: Final Touch - Custom Aliases and Functions
Create custom aliases or organize them into a directory for easier management:
Add Aliases in
.zshrc:alias ll="ls -lah" alias gs="git status" alias py="python3"Load Aliases from Separate Files:
if [ -d "$HOME/.alias" ]; then for file in $HOME/.alias/*; do [ -f "$file" ] && source "$file" done fi
Step 9: Regular Updates
Keep Zsh, Oh My Zsh, and plugins up to date:
Update Zsh:
brew upgrade zshUpdate Oh My Zsh and Plugins:
omz update
Sample .zshrc File
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
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
# Suppress Powerlevel10k instant prompt warnings
# typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet
# Path to your oh-my-zsh installation
export ZSH="$HOME/.oh-my-zsh"
# Theme
ZSH_THEME="powerlevel10k/powerlevel10k"
# Enable command auto-correction
ENABLE_CORRECTION="true"
# Display red dots whilst waiting for completion
COMPLETION_WAITING_DOTS="true"
# Plugins
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
history
vscode
kubectl
)
# Load Oh My Zsh
source $ZSH/oh-my-zsh.sh
# Custom Settings
# Java Home
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
# Vim Keybindings
bindkey -v
# Load Environment Variables from `.env` Directory
if [ -d "$HOME/.env" ] && [ "$(ls -A $HOME/.env)" ]; then
for file in $HOME/.env/*.env; do
[ -f "$file" ] && . "$file"
done
fi
# Load Aliases from `.alias` Directory
if [ -d "$HOME/.alias" ] && [ "$(ls -A $HOME/.alias)" ]; then
for file in $HOME/.alias/*.sh; do
[ -f "$file" ] && . "$file"
done
fi
# Additional Path Updates (already moved to system-paths.env)
export PATH="$PATH"
# Enable NVM (Node Version Manager)
if [ -d "$HOME/.nvm" ]; then
export NVM_DIR="$HOME/.nvm"
if [ -s "$NVM_DIR/nvm.sh" ]; then
source "$NVM_DIR/nvm.sh"
fi
fi
# iTerm2 Shell Integration
if [ -e "$HOME/.iterm2_shell_integration.zsh" ]; then
source "$HOME/.iterm2_shell_integration.zsh"
fi
# Backup and Update Aliases
alias backup-zshrc="cp ~/.zshrc ~/.zshrc.backup && echo 'Backup created at ~/.zshrc.backup'"
alias update-zsh="source ~/.zshrc && echo 'Reloaded .zshrc settings'"
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
Organizing Aliases and Environment Variables
To keep your configuration organized, you can separate your aliases and environment variables into dedicated directories:
Environment Variables: Store your environment variables in the
~/.envdirectory. Each file should have a.envextension and contain the necessary export statements.Aliases: Store your aliases in the
~/.aliasdirectory. Each file should have a.shextension and contain the alias definitions.
This organization helps maintain a clean and manageable .zshrc file, making it easier to update and troubleshoot.
Conclusion
With Zsh and Powerlevel10k configured, you now have a powerful terminal setup tailored to your workflow. This setup is highly customizable, so feel free to tweak it further as needed. Happy coding! 🚀
About the author
I am a Senior Software Engineer at BigBasket with over three years of experience in software development. Specializing in QA automation, CI/CD, and mobile automation, I am passionate about creating efficient workflows and sharing knowledge through blogs and articles.
I actively contribute to the tech community through my work, open-source projects, and insightful content. Feel free to connect with me on GitHub or LinkedIn to explore my projects and contributions.
Comments
Join the discussionNo comments yet. Be the first to comment.


