Posts

Install and Configure Oh My Zsh and use it in VSCode or Cursor

Table of Contents

If you use the simple Bash Terminal in your OS, you may want to give Zsh a try to use a faster and safer terminal with many more features. The simple Bash that exist in the common dist of Linuxes are not changed over years and just received some security fixes, but the community behind Zsh are improving it everyday and bring new useful plugins.

I use ‘Oh my Zsh’, Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.

Screenshot of Oh My ZSH in Yakuake

Installing it is easy, here we go:

First we install zsh itself

On Ubuntu/Kubuntu:

1
2
sudo apt update
sudo apt install zsh git curl wget unzip fontconfig

On Manjaro/Arch:

1
sudo pacman -Syu zsh git curl wget unzip fontconfig

And then ‘Oh my Zsh’ framework

Via Curl

1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Or via Wget

1
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

During installation it will ask you if you want to make it your default terminal and you may answer yes.

If you skipped that step or your distro did not change it automatically, you can change your default shell manually:

1
chsh -s "$(command -v zsh)"

Log out and back in after changing your default shell.

Configure Oh My Zsh

You can configure Oh My Zsh to change how it updates, enable or disable plugins, set the default user, and more. Open your own ~/.zshrc file without sudo:

1
nano ~/.zshrc

Here is a simple Linux-friendly example. Keep only the plugins you really use:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
export PATH=$HOME/bin:/usr/local/bin:$PATH
DEFAULT_USER="$(whoami)"

zstyle ':omz:update' mode auto
zstyle ':omz:update' frequency 1

plugins=(
  git
  vscode
)

if [[ -n $SSH_CONNECTION ]]; then
  export EDITOR='nano'
else
  export EDITOR='code --wait'
  # If you use Cursor instead of VSCode, use: export EDITOR='cursor --wait'
fi

Installing Powerlevel10k Theme

Powerlevel10k is a fast and customizable theme for Zsh. Oh My Zsh uses ~/.oh-my-zsh/custom as ZSH_CUSTOM by default, so first make sure its custom theme and plugin directories exist:

1
2
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
mkdir -p "$ZSH_CUSTOM/themes" "$ZSH_CUSTOM/plugins"

Then download Powerlevel10k:

1
2
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$ZSH_CUSTOM/themes/powerlevel10k"

Then set it as your theme in ~/.zshrc:

1
ZSH_THEME="powerlevel10k/powerlevel10k"

Install the font in the next section before you reload Zsh or open a new terminal. The first time Powerlevel10k loads, it will start a setup wizard to help you choose the prompt style.

Installing Font

Powerlevel10k needs a Nerd Font to show icons and prompt symbols correctly. If you use Powerlevel10k, install the Meslo font recommended for Powerlevel10k. If you use another theme later, regular Meslo Nerd Font is usually enough.

For Powerlevel10k

On Ubuntu/Kubuntu, install the Powerlevel10k Meslo font files manually for your current user:

1
2
3
4
5
6
7
8
9
font_dir="$HOME/.local/share/fonts/MesloLGS-NF"
mkdir -p "$font_dir"

wget -O "$font_dir/MesloLGS NF Regular.ttf" "https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf"
wget -O "$font_dir/MesloLGS NF Bold.ttf" "https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf"
wget -O "$font_dir/MesloLGS NF Italic.ttf" "https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf"
wget -O "$font_dir/MesloLGS NF Bold Italic.ttf" "https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf"

fc-cache -fv "$font_dir"

On Manjaro/Arch, install the matching package from the extra repository:

1
sudo pacman -S ttf-meslo-nerd-font-powerlevel10k

For other themes

On Ubuntu/Kubuntu, install Meslo Nerd Font manually for your current user:

1
2
3
4
5
6
7
8
9
font_dir="$HOME/.local/share/fonts/MesloNerdFont"
tmp_dir="$(mktemp -d)"

mkdir -p "$font_dir"
wget -O "$tmp_dir/Meslo.zip" https://github.com/ryanoasis/nerd-fonts/releases/latest/download/Meslo.zip
unzip -o "$tmp_dir/Meslo.zip" -d "$font_dir"
rm -rf "$tmp_dir"

fc-cache -fv "$font_dir"

On Manjaro/Arch, you can install Meslo Nerd Font from the package manager:

1
sudo pacman -S ttf-meslo-nerd

If you installed ttf-meslo-nerd-font-powerlevel10k for Powerlevel10k, you do not need to install ttf-meslo-nerd too.

You can verify the installed font name with:

1
2
fc-match "MesloLGS NF"
fc-match "MesloLGS Nerd Font Mono"

After installing the font, reload Zsh:

1
source ~/.zshrc

You can also just open a new terminal.

Optional: useful plugins

You can also install these two plugins for a better experience with Oh My Zsh:

1
2
3
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
git clone https://github.com/zsh-users/zsh-autosuggestions.git "$ZSH_CUSTOM/plugins/zsh-autosuggestions"
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"

Then enable them in the plugins=(...) list in ~/.zshrc. Keep zsh-syntax-highlighting last:

1
2
3
4
5
6
plugins=(
  git
  vscode
  zsh-autosuggestions
  zsh-syntax-highlighting # keep this last
)

Reload Zsh after changing the plugins:

1
source ~/.zshrc

You can also just open a new terminal.

Change the default terminal in VSCode or Cursor

Screenshot of OhMyZSH in VSCode

Ok so by now we have installed and configured Zsh, set Powerlevel10k as the theme, and installed a compatible font. VSCode or Cursor may still use the default Bash as the integrated terminal, so we want to change it to Zsh. After installing the font, restart VSCode or Cursor so it can detect it.

Now we can configure VSCode or Cursor to use Zsh. Add the following lines to settings.json or find them one by one in settings and apply them:

1
2
3
4
5
6
7
8
9
{
  "terminal.integrated.profiles.linux": {
    "zsh": {
      "path": "/usr/bin/zsh"
    }
  },
  "terminal.integrated.defaultProfile.linux": "zsh",
  "terminal.integrated.fontFamily": "'MesloLGS Nerd Font Mono', 'MesloLGS NF', monospace"
}