This is a collection of snippets used in Learning ZSH at LinkedIn Learning
r=$(( $RANDOM % 8 ))
echo "I'm thinking of a number between zero and eight. Can you guess it?"
vared -p "> " -c g
if [[ $g -eq $r ]]; then;
echo "Congratulations, $r is correct!"
else;
echo "Sorry, I was thinking of $r!"
fi
A colorful string:
PROMPT='[%F{164}%n%f@%F{135}%m%f %F{025}%d%f]%# '
Another colorful string:
PROMPT='[%F{009}%n%f@%F{015}%m%f %F{027}%d%f]%# '
Default string:
PROMPT='%m%# '
Right prompt showing the time:
RPROMPT=%*
Right prompt showing the current working directory:
RPROMPT=%d
Right prompt showing the collapsed user directory:
RPROMPT=%~
Empty right prompt:
RPROMPT=''
Function to show 256 colors in the foreground (%F
/%f
) and background (%K
/%k
). Adapted from the oh-my-zsh spectrum.zsh file.
function colors() {
for color in {000..255}; do
print -P "$color: %F{$color}████ Foreground %f%K{$color} Background %k"
done
}
Note: the file colors.png
provides an estimation of terminal colors. The actual colors displayed will vary slightly between applications.
Right prompt showing the remaining battery percentage, the date, and time:
RPROMPT='$(battery_pct_prompt) @ %D %*'