Skip to content

Instantly share code, notes, and snippets.

@xorspark
Created August 27, 2021 02:15
Show Gist options
  • Save xorspark/09f6ec63c71f61e2799539dea643d0bf to your computer and use it in GitHub Desktop.
Save xorspark/09f6ec63c71f61e2799539dea643d0bf to your computer and use it in GitHub Desktop.
Stream prompt was to make a pomodoro utility in pure bash and I needed a break from some JS insanity earlier today. I'll probably colorize it later and do some other fancy stuff at some point.
#!/usr/bin/bash
declare mins count colstart fmtmin fmtsec outp
mins="$1"
if [[ -z "$mins" ]]; then
printf 'Need a minute value.\n'
exit 1
fi
(( count=mins*60 ))
while (( count > 0 )); do
sleep 1
(( count-=1 ))
(( fmtmin=count / 60 ))
(( fmtsec=count % 60 ))
printf -v outp '%02dm%02ds' "$fmtmin" "$fmtsec"
(( colstart=$(tput cols) - ${#outp} ))
tput sc
tput cup 0 $colstart
printf '%s' "$outp"
tput rc
done
tput sc
tput cup 0 $(( $(tput cols) - 10 ))
printf ' '
tput rc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment