Overstap op ZSH: deel twee

Geschreven op en voor het laatst bijgewerkt op

Een tijdje terug ben ik overgestapt op ZSH. In het begin heb ik de configuratie van ZSH grotendeels standaard gelaten, maar degene die me langer dan vandaag kennen weten dat ik het niet kan laten om te kijken welke opties en mogelijkheden iets heeft.

Dus ook zo met ZSH. Het begon vrij eenvoudig / onschuldig: ik wilde een andere PROMPT met alleen de informatie die ik nuttig vond. Zo begon een langer proces dan ik gedacht had, waarvan de meeste tijd toch wel is gaan zitten in het configureren van het autocomplete (sub)systeem van ZSH.

Inmiddels ziet mijn ~/.zshrc er zo uit:

# Aliases list
if [ -f $HOME/.zshrc.d/aliases ]; then
	source $HOME/.zshrc.d/aliases
fi

# Compinit
autoload -Uz compinit
if [[ -n $HOME/.zcompdump(#qN.mh+24) ]]; then
	compinit
else
	compinit -C
fi

# Load compinit configuration if it exists
if [ -f $HOME/.zshrc.d/compinit ]; then
	source $HOME/.zshrc.d/compinit
fi

# Colors
autoload -Uz colors
colors

# Prompt
if (( $(env | grep -c SSH_CONNECTION) > 0 )); then
	PROMPT="%B%F{yellow}(SSH)%f%b %n@%m %B%F{green}%~%f%b $ "
else
	PROMPT=" %B%F{green}%~%f%b $ "
fi

if [ -f /usr/bin/pretty-git-prompt ]; then
	setopt PROMPT_SUBST
	RPROMPT="\$(pretty-git-prompt)"
fi

En mijn aliasen als volgt:

alias htop="htop -t -H"
alias top="htop"
alias free="free -h --si"
alias ff="fastfetch --logo none"
alias cmatrix="cmatrix -a -b -u 9"

En de grootste tijdslurper, de configuratie van compinit (in ~/.zshrc.d/compinit):

# Automatically highlight the first element of the completion menu
setopt MENU_COMPLETE

# Automatically list choices on ambiguous completion(s)
setopt AUTO_LIST

# Complete from both ends (of a word)
setopt COMPLETE_IN_WORD

# Place the cursor at the end of a completion
setopt ALWAYS_TO_END

# When a directory is autocompleted add a trailing slash
# at the end instead of a space
setopt AUTO_PARAM_SLASH

# Allows you to select in a menu
zstyle ":completion:*" menu select search

# Completion options
zstyle ":completion:*" complete-options true
zstyle ":completion:*" file-sort modification

# Autocomplete format options
zstyle ":completion:*:*:*:*:corrections" format "%F{yellow}!- %d (error: %e) -!%f"
zstyle ":completion:*:*:*:*:descriptions" format "%F{white}-- %B%D %d%b --%f"
zstyle ":completion:*:*:*:*:messages" format "%F{purple} -- %d -- %f"
zstyle ":completion:*:*:*:*:warnings" format "%B%F{yellow} -- no matches found -- %f%b"
zstyle ":completion:*:*:*:*:default" list-colors ${(s.:.)LS_COLORS}
zstyle ":completion:*:*:cd:*" tag-order local-directories directory-stack path-directories
zstyle ":completion:*" group-name ""
zstyle ":completion:*:*:-command-:*:*" group-order aliases builtins functions commands