Better zsh with Prezto

Written by | 12 minutes read | Tags linux, zsh, prezto | Comments

I haven't been a user of the oh-my-zsh because I found it too complicated. I was only interested in it's completion features. Therefore I ripped out this component, copied the completions from it and did the configuration on my own.

Then I tried fish-shell but wasn't satisfied. It lacks completion but has very good autosuggestions and amazing VGA terminal colors for certain types of commands.

prezto jumps in here - it's an optimized version of oh-my-zsh. It is fast, has completions out of the box, and the nice autosuggestions feature of the fish-shell.

Here is what you get in the end

Here is what you get in the end

(This article has been written with zsh 5.0.2 (i686-pc-linux-gnu), xfce4-terminal 0.6.3git-f7c72e5, tmux 2.2, and prezto 31 Jul 2015)


Grab the code:

$ git clone --recursive "${ZDOTDIR:-$HOME}/.zprezto"

Setup the configs:

$ for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^; do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"

Want to read more articles like that?

If you do the steps above, you will get the following files on your system:

lrwxrwxrwx   1 wm   wm       32 Jan 20 20:41 .zlogin -> /home/wm/.zprezto/runcoms/zlogin
lrwxrwxrwx   1 wm   wm       33 Jan 20 20:41 .zlogout -> /home/wm/.zprezto/runcoms/zlogout
drwxrwxr-x   5 wm   wm     4096 Jan 20 20:43 .zprezto
lrwxrwxrwx   1 wm   wm       35 Jan 20 20:42 .zpreztorc -> /home/wm/.zprezto/runcoms/zpreztorc
lrwxrwxrwx   1 wm   wm       34 Jan 20 20:42 .zprofile -> /home/wm/.zprezto/runcoms/zprofile
lrwxrwxrwx   1 wm   wm       25 Jan 20 20:33 .zsh -> /home/wm/git/dotfiles/zsh
lrwxrwxrwx   1 wm   wm       32 Jan 20 20:42 .zshenv -> /home/wm/.zprezto/runcoms/zshenv
-rwx------   1 wm   wm   192662 Jan 20 20:48 .zsh_history

I didn't need all the files, so I just cloned the repository as described above and put the following line at the beginning of my .zshrc:

# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
  source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"

Please note that you will be asked if you wish to overwrite your existing files (like .zshrc) or skip them, if they already exists.

Configure your .zpreztorc

This is the heart of prezto - here you enable modules and configure them.

The README says that the order of modules matters - I didn't follow them at first and was wondering why nothing changed:

Here is my .zpreztorc:

# Set the Prezto modules to load (browse modules).
# The order matters.
zstyle ':prezto:load' pmodule \
  'directory' \
  'utility' \
  'completion' \
  'git' \
  'prompt' \
  'syntax-highlighting' \
  'history-substring-search' \

Prompt color themes

Press prompt -l to get an overview of the available fonts:

$ prompt -l
Currently available prompt themes:
agnoster cloud damoekri giddie kylewest minimal nicoulaj paradox peepcode powerline pure skwp smiley sorin
steeef adam1 adam2 bart bigfade clint elite2 elite fade fire off oliver pws redhat suse walters zefram

And you can change the theme by typing $ prompt <name-of-the-theme>

Custom prompt color theme

I found the josh prompt very handy but changed it with parts from mseri prompt to create my own one, where I can see the full path in colors. You can find the theme I'm using as a gist prompt_wikimatze_setup.

Place this file in ~/.zprezto/modules/prompt/functions/prompt_wikimatze_setup and set the theme in your .zpreztorc:

zstyle ':prezto:module:prompt' theme 'wikimatze'

Get rid of options-groups

When pressing tab to complete a command and you don't like the category menus, you need to comment out the following lines in ~/.zprezto/modules/completion/init.zsh:

# Group matches and describe.
zstyle ':completion:*:*:*:*:*' menu select
# zstyle ':completion:*:matches' group 'yes'
# zstyle ':completion:*:options' description 'yes'
# zstyle ':completion:*:options' auto-description '%d'
# zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f'
# zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f'
# zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'
# zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f'
# zstyle ':completion:*:default' list-prompt '%S%M matches%s'
# zstyle ':completion:*' format ' %F{yellow}-- %d --%f'
# zstyle ':completion:*' group-name ''
# zstyle ':completion:*' verbose yes

All credit for this tipp goes to @jeromedalbert

Prezto without options-groups

Prezto without options-groups

Problems with tmux

After setting up everything, I started tmux and had a flickering cursor:


I tried a lot of different options in my .zpretzorc file but finally found the source of error in my tmux.conf file. I had to remove some active-window/active-border settings:

set-window-option -g window-style 'bg=#181818'
set-window-option -g window-active-style 'bg=black'
set-window-option -g pane-active-border-style ''

I think the issue is still there but I don't see it. The issue has something to do with asynchronity, as described in the issue on github.

Command-line completion speedup with prezto

Measure terminal startup time from a fresh oh-my-zsh:

time zsh -i -c "print -n"
zsh -i -c "print -n"  0,08s user 0,02s system 89% cpu 0,107 total

But command-line completions (like rake <tab>) take 2 seconds until it prints the available commands.

Measure terminal startup time in prezto:

time zsh -i -c "print -n"
zsh -i -c "print -n"  0,34s user 0,09s system 87% cpu 0,491 total

But rake <tab> takes around 1,2 seconds until it prints the available commands. And I'm doing this a lot more than opening new tabs, so that's a real speedup!

Want to read more articles like that?