Skip to content

Terminal

Zsh and Oh My ZSH

Oh My Zsh is a framework for Zsh, the Z shell.[1]

Install ohmyzsh

sudo apt install zsh
# install oh my zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Install Fonts

Info

Nerd Fonts is a project that patches developer targeted fonts with a high number of glyphs (icons). Specifically to add a high number of extra glyphs from popular 'iconic fonts' such as Font Awesome, Devicons, Octicons, and others.[2]

Download Nerd Fonts and update Font cache:

mkdir -p ~/.local/share/fonts
cd ~/.local/share/fonts
wget https://github.com/ryanoasis/nerd-fonts/releases/latest/download/JetBrainsMono.tar.xz
tar -xf JetBrainsMono.tar.xz
rm JetBrainsMono.tar.xz
fc-cache -fv

select JetBrainsMono <Nerd fonts> in preferences-->profiles->Text->Custom font

restart terminal and test icons

echo -e "\ue62b \uf296 \ue62b"

200

Install Theme

[!WARNING] Nerd-fonts is prepared for displaying the powerlevel10k icon

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

Open ~/.zshrc, find the line that sets ZSH_THEME, and change its value to "powerlevel10k/powerlevel10k" as following:

# correct the old ZSH_THEME or can not find p10k command
ZSH_THEME="powerlevel10k/powerlevel10k"

then restart terminal and config themes

p10k configure

🥳 assets/Pasted image 20250105153158.png

Install Plugins

[!NOTE] You can update plugins manually use omz update, or the system will periodically prompt you for updates.

install extra plugin from GitHub

git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/Pilaton/OhMyZsh-full-autoupdate.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/ohmyzsh-full-autoupdate
git clone https://github.com/fdellwing/zsh-bat.git $ZSH_CUSTOM/plugins/zsh-bat

activate the built-in or extra plugins in ~/.zshrc

plugins=(
    command-not-found
    extract
    docker
    history-substring-search
    z
    zsh-autosuggestions
    zsh-syntax-highlighting
    ohmyzsh-full-autoupdate
)

Note

plugin config must before the source $ZSH/oh-my-zsh.sh

Command-not-found

this plugin uses the command-not-found package for Zsh to provide suggested packages to be installed if a command cannot be found.

Extract

This plugin defines a function called extract that extracts the archive file you pass it, and it supports a wide variety of archive filetypes.

The Plugin enables searching through commands history by typing a partial match of previous command.

Use ⬆️ or ⬇️ to match commands from history assets/Pasted image 20250105170317.png

Z

Zsh-z is a command-line tool that allows you to jump quickly to directories that you have visited frequently or recently.[3]

assets/Pasted image 20250105164146.png 1. cd needs the specific directory, keywords of your directory which visited before is enough for z 2. tab with z show the scope that the keywords would match. assets/Pasted image 20250105164354.png

Zsh-autosuggestions

It suggests commands based on your history of previous commands and completions assets/Pasted image 20250105154644.png

Zsh-syntax-highlighting

Alert the wrong syntax with red color assets/Pasted image 20250105155224.png

Zsh-bat

This plugin will replace cat with batcat

sudo apt install bat

assets/Pasted image 20250105174713.png

VS Code Terminal Config

To config VS Code terminal, add the following properties to your user settings.json to enable Zshand monospace fonts.

[!NOTE] A restart is required for font changes to take effect.

{
  "terminal.integrated.fontFamily": "JetBrainsMono Nerd Font Mono"
  "terminal.integrated.fontSize": 14,
  "terminal.integrated.shellIntegration.enabled": true,
  "terminal.integrated.defaultProfile.windows": "PowerShell",
  "terminal.integrated.defaultProfile.linux": "zsh"
}

Tmux

install via sudo apt install tmux config

git clone --single-branch https://github.com/gpakosz/.tmux.git ~/.local/share/oh-my-tmux

mkdir -p ~/.config/tmux

ln -s ~/.local/share/oh-my-tmux/.tmux.conf ~/.config/tmux/tmux.conf

cp ~/.local/share/oh-my-tmux/.tmux.conf.local ~/.config/tmux/tmux.conf.local

# make sure read the latest config
tmux kill-server

prefix is Ctrl+a/b

kill all session tmux kill-server

split panes prefix + - horizontally split panes prefix + _ vertically

switch in different split panes prefix + h/j/k/l or ⬆️/⬅️/➡️/⬇️

scroll up or down in split panes prefix + [ into copy mode, then - ⬆️/⬇️ or PgUp/PgDn - g to specify which line to go

keep session running in background

tmux new -s proxy
sing-box-cli run

press ctrl+B then d to detach go back to session

tmux attach -t proxy

Shortcut

Use Tab to autocomplete file, directory, commands

Erase the whole line via Ctrl+U Clear screen using Ctrl+L

Home or End (Ctrl+A, Ctrl+E) can jump to the front or the end of the command

zsh-autosuggestions with ➡️ gets the command from history, but sometimes the partial commands, words need to be modified to run,Ctrl+U remove the word before the cursor

Ctrl+D terminates the current SSH connection

history-substring-search allows us to use keyword with ⬆️, ⬇️ to filter commands from history

Ctrl+C to kill the running program, Ctrl+Z to suspend it

Use Ctrl+Shift+C and Ctrl+Shift+V to copy and paste

Reference

  1. The Only 5 Zsh Plugins You Need
  2. ZSH + Oh My ZSH! on Windows with WSL
  3. 12 Linux Terminal Shortcuts Every Power Linux User Must Know
  4. Plugins-oh my zsh