adrianwong programmer · retired coal miner

A minimal ZSH configuration

I switched to ZSH on macOS a few years ago. As part of that switch, I also installed oh-my-zsh, which was (and still is) a commonly recommended framework to install alongside ZSH. oh-my-zsh is pretty neat - I’d enable some plugins, select a theme, and within a few minutes I’d have a sensibly configured, good-looking shell that is rather enjoyable to use.

However, that out-of-the-box convenience has a trade-off in that oh-my-zsh is fairly bloated. That, and it abstracts away ZSH configurations that I would’ve been forced to learn when adopting ZSH. Having recently installed ZSH on Arch Linux, I figured it was a good opportunity to try rolling my own (minimal) ZSH configuration, instead of once again going down the oh-my-zsh route.


1 zstyle ':completion:*' menu select
2 bindkey '^[[Z' reverse-menu-complete
4 zstyle ':completion:*' special-dirs true
5 zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'

As I understand it, zstyle takes a context and a style (why call it “style” instead of “configuration”?), and applies the style to the context. The context is a colon-separated string, where each subsequent colon denotes a more specific context. E.g. :vcs_info:git:* is more specific than :vcs_info:*. A style that is applied to a more specific context takes precedence over a style that is applied to a less specific one.

Snippet explanation:

Left prompt

4 PROMPT='%B[%n:%F{yellow}%25<..<%~%f%<<]%b$ '

Comprehensive documentation on configuring the prompt can be found here. My prompt is very similar to the prompt from the mh theme - it’s what I’ve used for as long as I’ve had ZSH and I like it.

Snippet explanation:

Right prompt (Git)

 1 autoload -Uz vcs_info
 2 precmd_vcs_info() { vcs_info }
 3 precmd_functions+=( precmd_vcs_info )
 5 zstyle ':vcs_info:*' enable git
 6 zstyle ':vcs_info:*' check-for-changes true
 7 zstyle ':vcs_info:*' stagedstr '%F{green}●%f'
 8 zstyle ':vcs_info:*' unstagedstr '%F{red}●%f'
 9 zstyle ':vcs_info:git:*' formats '[%F{cyan}%b%f%c%u]'
11 RPROMPT='%B$vcs_info_msg_0_%b'

Snippet explanation:


1 source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
3 source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
4 bindkey '^[[A' history-substring-search-up
5 bindkey '^[[B' history-substring-search-down
7 source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

(All three plugins are downloadable via pacman.)

Snippet explanation:

And that’s it! I’m sure the number of configurations/plugins will grow with time as I uncover more conveniences that oh-my-zsh has provided without me knowing. At the time of writing, though, the ones mentioned above have been sufficient.