Skip to content

Instantly share code, notes, and snippets.

@OnCloud125252
Last active March 20, 2024 02:22
Show Gist options
  • Save OnCloud125252/57fd36756b15b485e05709e876df896f to your computer and use it in GitHub Desktop.
Save OnCloud125252/57fd36756b15b485e05709e876df896f to your computer and use it in GitHub Desktop.
Setting up Zsh with Oh-My-Zsh and custom theme on Ubuntu

Before Starting

Links

Supported Installation

Operating System Tool
Ubuntu 22.04.2 LTS zsh 5.8.1

Note

Each command is separate with a blank line, please execute them separately.

Installation

Install dependencies

sudo apt install vim curl git

It's recommended to install Nerd Font in this step to avoid display problems.
If Nerd Font isn't properly installed, you will not be able to experience the full functionality of Powerlevel10k.

  1. Install dependencies:
    • sudo apt install fontconfig
  2. Download and install one of the nerd font:
  3. Install fonts:
    • Move all fonts to /usr/local/share/fonts/TTF
    • If the directory doesn't exist, create one
    • Rebuild the font cache with fc-cache -f -v

Install Zsh

sudo apt install zsh

sudo chsh -s $(which zsh)

Install On My Zsh

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

Install Powerlevel10k

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

Switch the theme to Powerlevel10k by editing the config file which located in /home/$USER/.zshrc (~/.zshrc).
Change the line ZSH_THEME="robbyrussell" to ZSH_THEME="powerlevel10k/powerlevel10k".

Apply the changes by executing source /home/$USER/.zshrc (source ~/.zshrc).

The Powerlevel10k configuration wizard should be started automatically.
If it doesn't, execute p10k configure to start the configuration wizard.
Choose your favorites configuration!

My personal favorite configs are: 3121132342221y1y (Start from "Prompt Style")

Install plugins (Optional)

Zsh-Completions
Additional completion definitions for Zsh.

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

Zsh-Autosuggestions
It suggests commands as you type based on history and completions.

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

Zsh-Syntax-Highlighting
It enables highlighting of commands whilst they are typed at a zsh prompt into an interactive terminal.

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

Finally, add the following configuration to .zshrc:

plugins=(
  git
  zsh-completions 
  zsh-autosuggestions 
  zsh-syntax-highlighting
)

Apply the changes by executing source /home/$USER/.zshrc (source ~/.zshrc).

Finishing

Enjoy your perfect terminal with fantastic looking, autosuggestions and syntax-highlighting~

Little tip

Add the following lines to the end of .zshrc file to anchor the prompt to the bottom of the terminal window.

# Fix prompt at the bottom of the terminal window
alias clear="clear && printf '\n%.0s' {1..100}"
printf '\n%.0s' {1..100}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment