How to setup a minimal zsh prompt
A minimal prompt for zsh embraces simplicity and focuses on providing essential information without overwhelming the user
Having an informative prompt in a shell is important for several reasons. An informative prompt provides valuable context about the current shell environment. It typically includes information such as the username, hostname, current working directory, and other relevant details. This helps users quickly understand their location and the system they are interacting with, reducing the chances of confusion or executing commands in the wrong context.
Apart from that, a well-designed prompt can provide visual feedback on the state of the shell. For example, it can change colors or display symbols to indicate successful or failed commands, the presence of background jobs, or the status of version control repositories. This visual feedback aids in quickly identifying important information without explicitly checking command outputs or running separate commands. It can also display the current working directory, which is particularly helpful when navigating through the file system.
By having a clear representation of the directory structure in the prompt, users can easily understand their location and navigate to different directories with ease, without needing to execute additional commands.
This is the zsh prompt that I use. You can set it up just by copying it into your .zshrc file:
PROMPT="%B%F{#af8700}[%j]%F{#808080}%n%F{#af8700}@%F{#808080}%m%F{#af8700}:%F{#d75f00}%4c%f%b%F{white}>"
- Number of processes running in the background:
%j
- User name:
%n
- Host name:
%m
- Current folder up to 4 levels:
%4c%f%b
bindkey -v
ESC
. But
I use a different color scheme (yellow foreground) for command line
editing, so that I know which mode I'm currently in:
# [jobs]user@host:current path up to 4 levels>
function set-prompt () {
case ${KEYMAP} in
# Yellow foreground for vim command mode
(vicmd) PROMPT="%B%F{#af8700}[%j]%F{#808080}%n%F{#af8700}@%F{#808080}%m%F{#af8700}:%F{#d75f00}%4c%f%b%F{white}>%F{yellow}" ;;
# White foreground for anything else
(*) PROMPT="%B%F{#af8700}[%j]%F{#808080}%n%F{#af8700}@%F{#808080}%m%F{#af8700}:%F{#d75f00}%4c%f%b%F{white}>" ;;
esac
}
function zle-line-init zle-keymap-select {
set-prompt
zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select