中文

Oh My Zsh: Customizing the Terminal

Today I spent an hour upgrading my terminal. macOS ships with Zsh, but its default setup is bare, so I used Oh My Zsh and a few other tools to make it friendlier. Here is what I changed.

Autosuggestions

The zsh-autosuggestions plugin shows a gray suggestion based on your command history as you type. Type gi and it already offers the long git clone command you ran earlier; press → to accept it.

sh
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=(...) list in ~/.zshrc.

Editing .zshrc in VS Code

Instead of Nano, I open the config in VS Code:

sh
code ~/.zshrc

If code isn’t found, open VS Code, press Cmd + Shift + P, and run Shell Command: Install 'code' command in PATH.

Ghostty

I moved from Terminal.app to Ghostty, a GPU-accelerated terminal written in Zig.

sh
brew install --cask ghostty

Its config lives at ~/.config/ghostty/config. Mine:

font-family = "JetBrains Mono"
font-size = 14
theme = "Catppuccin Mocha"
background-opacity = 0.85
background-blur-radius = 20
cursor-style = bar
cursor-style-blink = true
window-decoration = true

Starship

Starship is a prompt that shows Git status, how long the last command took, and tool versions.

sh
brew install starship

Add this line to the end of ~/.zshrc:

sh
eval "$(starship init zsh)"

I use the pastel powerline preset:

sh
starship preset pastel-powerline -o ~/.config/starship.toml

Syntax highlighting

zsh-syntax-highlighting colors commands as you type: green when the command exists, red when it doesn’t, so typos show up before you press Enter.

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

Add zsh-syntax-highlighting to plugins in ~/.zshrc. It should be the last plugin in the list.

My .zshrc

A note on this file: it still loads Powerlevel10k, the theme I used before Starship. Since starship init runs last, Starship’s prompt replaces p10k’s, so the p10k lines (the instant-prompt block, ZSH_THEME, and ~/.p10k.zsh) are leftovers I can remove. The syntax-highlighting plugin also still needs adding to plugins.

sh
typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet

if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

export ZSH="$HOME/.oh-my-zsh"

ZSH_THEME="powerlevel10k/powerlevel10k"

plugins=(git zsh-autosuggestions)

source $ZSH/oh-my-zsh.sh

[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

export PATH="$HOME/.local/bin:$PATH"
eval "$(starship init zsh)"

Undertide