MacOS: Revamp your Zsh terminal
Make your Zsh terminal appear like one belonging to a software engineer.
Photo by Gabriel Heinzer on Unsplash
As software professionals, we love to make things look cool, don't we? Imagine you are presenting a demo to a large audience and all they are seeing is a black and white terminal. Well, that would be hard to follow and many would lose interest. Instead, if you could present a terminal filled with colours, autocompletion and some syntax highlighting, wouldn't that be great?
Well, what are we waiting for? Let's go ahead and revamp our Zsh terminal.
Oh My Zsh
Oh My Zsh (pronounced oh my zee shell) is an open source, community-driven framework for managing your zsh configuration.
Oh My Zsh will not make you a 10x developer...but you may feel like one.
Install Oh My Zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
As soon as the installation is complete, you will see a hint of colour on your terminal.
Oh My Zsh
creates a new .zshrc
file. Copy the custom alias, paths and secrets from your backup .zshrc
file and paste it at the end of the new file.
Save the file and source it.
source ~/.zshrc
Powerlevel10k
Powerlevel10k is a theme for Zsh. It emphasizes speed, flexibility and out-of-the-box experience. It boosts the terminal with a nice new font and enables a fully customizable look and feel.
Install the Meslo Nerd Font
by following the instructions mentioned here.
After installing the Font, Open Terminal → Settings → Profiles → Text, click Change under Font and select MesloLGS NF
family. If you're unable to spot the Font, ensure you select "All Fonts" under the "Collection" option. Refer to the picture below.
Install Powerlevel10k
using the command below:
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
Next step is to use the Powerlevel10k
these for Oh My Zsh
. To do that, open the ~/.zshrc
file and edit the value of the existing field ZSH_THEME
from robbyrussell
to powerlevel10k/powerlevel10k
as follows:
ZSH_THEME="powerlevel10k/powerlevel10k"
After installation, restart Zsh
using the following command:
exec zsh
This will open the Powerlevel10k
configuration wizard.
Here are the options that worked best for me:
Prompt | Answer (Option entered) |
Does this look like a diamond (rotated square)? | Yes (y) |
Does this look like a lock? | Yes (y) |
Does this look like an upward arrow? | Yes (y) |
Do all these icons fit between the crosses? | Yes (y) |
Prompt Style | Lean (1) |
Character Set | ASCII (2) |
Prompt Colors | 256 (1) |
Show current time? | No (n) |
Prompt Height | One line (1) |
Prompt Spacing | Compact (1) |
Prompt Flow | Fluent (2) |
Enable Transient Prompt | No (n) |
Instant Prompt Mode | Verbose (1) |
Apply changes to ~/.zshrc | Yes (y) |
Try a command such as
cd ~/Documents
You will see the an immediate change:
zsh-autosuggestions
zsh-autosuggestions suggests commands as you type based on history and completions.
Install the zsh-autosuggestions
plugin using the following command:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Add the plugin to the list of existing plugins for Oh My Zsh
to load (inside ~/.zshrc
)
plugins=(git zsh-autosuggestions)
Source the .zshrc
using the following command:
source ~/.zshrc
Try to type some commands you have used before and you will see that the terminal suggests an auto-completion. To choose the suggested option, simply click the right arrow key.
zsh-syntax-highlighting
zsh-syntax-highlighting provides syntax highlighting for Zsh
. It enables highlighting of commands whilst they are typed at a Zsh
prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors.
Install the zsh-syntax-highlighting
plugin using the following command:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Add the plugin to the list of existing plugins for Oh My Zsh
to load (inside ~/.zshrc
)
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
Source the .zshrc
using the following command:
source ~/.zshrc
Try to type some commands. You will find that the terminal highlights valid commands in green and invalid commands in red.
Kubernetes Joy
For Kubernetes users, as soon as you type kubectl
, the active context from the kubeconfig
file is shown at the right of the terminal.
If the current namespace is anything other than default, it shows the custom namespace as well. In the below example, the context name is istio
and the namespace is temp
.
Wow, now that's an awesome upgrade!
Happy coding!