Skip to content

Instantly share code, notes, and snippets.

@romkatv
Created March 3, 2024 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romkatv/15d5ebb8122417903cbe7fe9c5dba47b to your computer and use it in GitHub Desktop.
Save romkatv/15d5ebb8122417903cbe7fe9c5dba47b to your computer and use it in GitHub Desktop.
Zsh prompt wave
function metronome() {
local -rF tick_sec=0.3
while true; do
zselect -t $((int(ceil(tick_sec * 100))))
print 2>/dev/null || break
done
}
function update-prompt() {
local -ri period=7
typeset -gi phase
(( phase = (phase + 1) % period ))
local prompt=${(L)${(%)PS1}}
local -i i
for ((i = phase + 1; i <= $#prompt; i += period)); do
prompt[i]=${(U)prompt[i]}
done
PS1=${prompt//\%/%%}
zle .reset-prompt
if (( ARGC == 2 )); then
zle -F $1
else
local REPLY
while read -t0 -u$1; do; done
fi
}
() {
local fd
zmodload zsh/zselect zsh/mathfunc zsh/system &&
exec {fd} < <(metronome) &&
zle -F $fd update-prompt
}
PS1='%n@%m %~ %# '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment