Final result:

WSL7.png

WSL8.png

The previous article covered a beginner’s guide to WSL2. Next, I will introduce how to customize the terminal.

1. Install ZSH

1
sudo apt install zsh

Then configure it as the default shell.

1
2
cat /etc/shells # List the shells available on the system
chsh -s /bin/zsh # Set zsh as the default shell, or use chsh -s $(which zsh)
Note
This only changes the shell for the current account. root and other accounts need to be configured separately.
If you see su: Authentication failure when logging in as root with su, root may not have a password set. Use the following command to set the root password:
1
sudo passwd root

Run exit and open the terminal again. It will now use the zsh shell, and you will see the following screen:

zsh.png

You can press 1 to customize it according to the instructions, press 2 to use the recommended configuration, or press 0 or q to leave it unchanged. When installing ohmyzsh later, a new .zshrc will be generated automatically, and the old .zshrc will be renamed to .zshrc.pre-oh-my-zsh.

1
echo $SHELL # Check the shell currently in use

2. Install ohmyzsh

Run the following command:

1
2
sh -c "$(curl -fsSL https://install.ohmyz.sh/)"
# This pulls the repository from GitHub. If it is slow, try switching networks.

There will be a prompt during the process. Just press Enter.

Note
Because the shell has changed, the original configuration in ~/.bashrc will not take effect in zsh. You can migrate it to ~/.zshrc yourself.

3. Switch Themes

You can choose any theme you like. ohmyzsh includes some themes by default, which you can browse in ohmyzsh Themes.
Here I recommend the theme I have been using: powerlevel10k. It needs to be installed manually, so the installation method is introduced below.

Install Nerd Fonts

Go to the Nerd Fonts website and download a font you like. I use UbuntuMono Nerd Font. Then install it directly on Windows. I am using WSL2 here; if you use another system, install it on the corresponding system. After extracting the archive, select all .ttf files, right-click, and install them.

nerdfonts.png

Then switch the terminal font. Tabby is used as the example here.

tabby1.png

There are usually three options. They differ in details such as character width and spacing. You can try them one by one and choose the one you like most from the preview below.

tabby2.png

Install powerlevel10k

Run the following command:

1
2
3
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k"
# You can use the official mirror on Gitee to speed up the download
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k"

Then edit ~/.zshrc and set the value of ZSH_THEME to powerlevel10k/powerlevel10k. Open the terminal again, and powerlevel10k will show its initial setup wizard. Follow the guide to configure it.

4. Install Plugins

ohmyzsh includes many plugins by default. You can enable them yourself. See ohmyzsh Plugins.
Here are a few plugins I recommend.

zsh-syntax-highlighting

This plugin highlights the commands you type. Install it with the following command:

1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Then add zsh-syntax-highlighting to the plugins entry in ~/.zshrc.

zsh-autosuggestions

This plugin provides smart suggestions for the command you are typing based on commands you have entered before. Install it with the following command:

1
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Then add zsh-autosuggestions to the plugins entry in ~/.zshrc.

zsh-completions

This plugin enhances command completion and provides richer, smarter command and option suggestions. Install it with the following command. Enabling this plugin is slightly different from the previous ones, so refer to the zsh-completions installation instructions.

1
2
git clone https://github.com/zsh-users/zsh-completions.git \
${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions

Then add the following configuration before the source "$ZSH/oh-my-zsh.sh" line in ~/.zshrc.

1
2
3
fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src
autoload -U compinit && compinit
source "$ZSH/oh-my-zsh.sh"

Refresh the zsh completion cache:

1
2
rm -f ~/.zcompdump # Delete the old cache
compinit # Reinitialize completion

Here is my final .zshrc configuration:

zshrc.png

By the way, here is a GitHub repository that collects many ZSH frameworks, plugins, themes, and tutorials: awesome-zsh-plugins.

5. About fastfetch

fastfetch is a tool that retrieves system information and displays it in a nice-looking format. It is useful and fun, so here is how to install and configure it.

For installation, refer to fastfetch installation.
The version installed with apt on Ubuntu is several versions behind. If you want the latest version, install it from the GitHub repository yourself. Example:

1
2
3
4
5
6
7
# Find the latest download link for your computer architecture and replace the link below.
# The part before the URL is the saved file name.
curl -L -o fastfetch-linux-amd64.deb https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-amd64.deb
# Install it with dpkg
sudo dpkg -i fastfetch-linux-amd64.deb
# Uninstall it if needed
sudo dpkg -r fastfetch

Its configuration file is located at ~/.config/fastfetch/config.jsonc. If the folder or file does not exist, create it yourself.

1
2
3
mkdir -p ~/.config/fastfetch
cd ~/.config/fastfetch
touch config.jsonc

Then edit the configuration yourself. You can refer to the official fastfetch presets and the fastfetch configuration wiki.

Finally, run fastfetch to try it out.