Created
March 3, 2024 15:14
-
-
Save romkatv/15d5ebb8122417903cbe7fe9c5dba47b to your computer and use it in GitHub Desktop.
Zsh prompt wave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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