Tuning the zsh shell using zinit and powerlevel10k

João Matias
4 min readFeb 6, 2021

As a programmer, the command line terminal is one of the most important tools I use. By default, the appearance of this application is very plain, but there are ways to customize its looks and functionality. So, I’d like to share some of my favorite tools that can improve the experience while using it. In particular, I’m a big fan of zinit and powerlevel10k. You can also see my shell configuration in my dotfiles.

I switched to zsh (pronounced z-shell) a while back when it became the default in macOS Catalina (replacing bash). It offers some additional features and can be easily customized using frameworks like oh-my-zsh or prezto. Despite the convenience, these frameworks add a lot of bloat to the shell configuration of which most people only use part, so I kept searching for more minimal tools that achieve similar results.

If you like to have an idea of the final result, here is a video recorded using asciinema.

One of those tools is zinit!

zinit

zinit is a project that provides the option to combine shell configuration scripts from multiple sources (including plugins from oh-my-zsh and prezto!). Furthermore, it gives some control over the timing in which each script is loaded, including after displaying the shell prompt, thus reducing the startup time. The main setback is its learning curve that can be countered by the extensive documentation and examples available.

After installing zinit, the configuration scripts can be taken from github repositories (or gitlab, or bitbucket for that matter) by adding a command like the following in .zshrc

zinit light-mode OMZL::history.zsh

The purpose of the command in the example is setting some aliases and environment variables that manage the history of the terminal shell. More concretely, it runs the script history.zsh in the lib folder of the oh-my-zsh github repository since, in zinit, OMZL can be used as an abbreviation for that location. The modifier light-mode disables some reporting and tracking functionalities used to debug the script and that usually are not needed.

It is also possible to combine multiple commands using a for syntax as below

zinit light-mode depth=1 for \
romkatv/powerlevel10k \
OMZL::history.zsh \
blockf OMZL::completion.zsh

In particular, this command also starts up the shell theme powerlevel10k that will be mentioned again later.

More plugins!

I use a few other plugins that are loaded by the following command in .zshrc.

zinit wait lucid light-mode depth=1 for \
atinit"zicompinit; zicdreplay" \
zdharma-continuum/fast-syntax-highlighting \
zdharma-continuum/history-search-multi-word \
atload"bindkey '^[[A' history-substring-search-up; \
bindkey '^[[B' history-substring-search-down" \
zsh-users/zsh-history-substring-search

There are a few modifiers that make the plugins work flawlessly and that you may read about in the zinit wiki. The most relevant is wait, which enables the turbo-mode. This option makes the shell wait for the prompt to be displayed before loading the associated plugins.

The last two plugins listed in the command help navigating through entries in the commands history. zsh-users/zsh-history-substring-search allows the users to scroll, using the up and down arrows, through the entries of the history that contain some given subtstrings. zdharma-continuum/history-search-multi-word performs a similar action by pressing Control+R, but has a slightly different interface.

zdharma-continuum, the group that maintains zinit, also maintains some impressive plugins that can replace older and slower plugins that have been shared for years on the internet. One example is Fast Syntax Highlighting. This plugin highlights the shell commands to improve their appearance and readability. It does so very quickly and shows a significant difference in speed when compared to other options like zsh-syntax-highlighting (check the video below).

(source: fast-syntax-highlighting performance)

powerlevel10k

powerlevel10k is a theme based on vim’s powerline so its look does not disappoint. It stands out from other similar looking themes due to its responsiveness. On my daily use, I’ve never noticed it lagging, even when pressing the return key repeatedly. Furthermore, it has the option to load instantly uppon openning a new terminal session by adding the following in .zshrc

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

It is also very easy to configure and provides plently of options to tweak. Just use the command p10k configure (example below) to run the wizard. After configuring the theme, the settings are saved in the file .p10k.zsh which can be edited separately, too (at the user’s risk, though). For example, one can place the time in the left side of the shell by changing the property POWERLEVEL9K_LEFT_PROMPT_ELEMENTS, among other options.

I hope you enjoyed these tips and learned something new! Feel free to reach out if you have comments.

--

--