Skip to content

Instantly share code, notes, and snippets.

@philpennock
Last active November 11, 2021 00:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philpennock/acf6f7c19664b0ef79b0c1a405848a37 to your computer and use it in GitHub Desktop.
Save philpennock/acf6f7c19664b0ef79b0c1a405848a37 to your computer and use it in GitHub Desktop.
topleft="$(tput cup 0 0)"; nl="$(tput el)"$'\n'; invis="$(tput civis)"; vis="$(tput cvvis)"
push="$(tput sc)"; pop="$(tput rc)"
PS1="${topleft}%F{green}%D{%D %r}%f${nl}%~${nl}%# "
eval "TRAPUSR1() { print -Pn '${push}${invis}${topleft}%F{green}%D{%D %r}%f${nl}${pop}${vis}' }"
unset topleft nl invis vis push pop
p=$$; while sleep 1; do kill -s USR1 $p || exit; done &! unset p
# modified to do "|| exit" after the kill, so that if the kill fails, the child exits, so when parent dies, child will too.
# center-align version
topleft="$(tput cup 0 0)"; nl="$(tput el)"$'\n'; invis="$(tput civis)"; vis="$(tput cvvis)"
push="$(tput sc)"; pop="$(tput rc)"
align="$(printf "%$(((${${=$(stty size)}[2]}-${#${(%):-%D{%D %r\}}})/2))s")"
PS1="${topleft}${align}%F{green}%D{%D %r}%f${nl}%~${nl}%# "
eval "TRAPUSR1() { print -Pn '${push}${invis}${topleft}${align}%F{green}%D{%D %r}%f${nl}${pop}${vis}' }"
unset topleft nl invis vis push pop align
p=$$; while sleep 1; do kill -s USR1 $p || exit; done &! unset p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment