dotfiles/polybar/.config/polybar/scripts/poly-pomo

42 lines
1002 B
Bash
Executable File

#!/usr/bin/env sh
run_notify() {
pomo notify &
PID_NOTIFY="$!"
echo "$PID_NOTIFY" >"${XDG_RUNTIME_DIR:-$HOME}"/.running-pomo.lock
}
# create background notify process; close it when this process is killed
close_notify() {
lockfile="${XDG_RUNTIME_DIR:-$HOME}"/.running-pomo.lock
[ -f "$lockfile" ] && kill "$(cat "$lockfile")"
kill "$PID_NOTIFY"
rm "${XDG_RUNTIME_DIR:-$HOME}"/.running-pomo.lock
}
trap close_notify EXIT
restart_notify() {
close_notify
run_notify
}
if [ -z "$1" ]; then
run_notify
while true; do
display=$(pomo clock)
# replace W (work)
# B (break)
# P (paused) with pomodoro symbols
# remove seconds *except for* when 00 minutes reached
display=$(echo "$display" | sed -e 's/--:--/ /;s/P.*$/  /;s/W/ /;s/B/ /;/00:/! { s/:[[:digit:]]\+$// }')
echo "$display"
sleep 1
done
elif [ "$1" = "toggle" ]; then
pomo pause
restart_notify
elif [ "$1" = "restart" ]; then
pomo stop
restart_notify
fi