aboutsummaryrefslogtreecommitdiff
path: root/archive/timer.bak
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-05-10 22:57:02 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-05-10 22:57:02 +0200
commit3cd9138c9d8fb9be248c75330cca9da47f4d2e8a (patch)
treeb3b677a9c1a474589f45d20953028a987fa73b80 /archive/timer.bak
parent83f7fe4b8402bab171d110703a1b1115efbc9b28 (diff)
downloadbin-3cd9138c9d8fb9be248c75330cca9da47f4d2e8a.tar.gz
bin-3cd9138c9d8fb9be248c75330cca9da47f4d2e8a.zip
added a whole bunch of scripts
Diffstat (limited to 'archive/timer.bak')
-rw-r--r--archive/timer.bak68
1 files changed, 68 insertions, 0 deletions
diff --git a/archive/timer.bak b/archive/timer.bak
new file mode 100644
index 0000000..fa8883c
--- /dev/null
+++ b/archive/timer.bak
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+# timer DURATION [MESSAGE...]
+# examples: timer 25m "Pomodoro done" | timer 90s "Break over"
+
+set -euo pipefail
+
+dur="${1:-}"
+shift || true
+msg="${*:-Time is up}"
+
+if [ -z "$dur" ]; then
+ echo "usage: timer 25m \"Pomodoro done\" | timer 90s \"Break over\""
+ exit 1
+fi
+
+# Parse duration: Ns or Nm (only)
+case "$dur" in
+ *m) total=$(( ${dur%m} * 60 ));;
+ *s) total=$(( ${dur%s} ));;
+ *) echo "Bad duration: $dur (use e.g. 25m or 90s)"; exit 1;;
+esac
+
+# Terminal helpers
+cols=$(tput cols 2>/dev/null || echo 80)
+barw=$(( cols - 22 ))
+[ "$barw" -lt 10 ] && barw=10
+
+hide_cursor() { tput civis 2>/dev/null || true; }
+show_cursor() { tput cnorm 2>/dev/null || true; }
+cleanup() { show_cursor; printf "\n"; }
+trap cleanup EXIT INT TERM
+
+hide_cursor
+
+# ANSI colors (no external deps)
+YELLOW=$'\033[33m'
+GREEN=$'\033[32m'
+DIM=$'\033[2m'
+RESET=$'\033[0m'
+
+secs="$total"
+start_msg="${msg}"
+
+while [ "$secs" -gt 0 ]; do
+ mm=$(( secs / 60 ))
+ ss=$(( secs % 60 ))
+
+ done=$(( total - secs ))
+ pct=$(( done * 100 / total ))
+
+ fill=$(( barw * done / total ))
+ empty=$(( barw - fill ))
+
+ # Build progress bar
+ bar="$(printf "%${fill}s" "" | tr ' ' '=')"
+ pad="$(printf "%${empty}s" "")"
+
+ printf "\r${YELLOW}T-%02d:%02d${RESET} ${DIM}[${bar}>${pad}]${RESET} %3d%% " \
+ "$mm" "$ss" "$pct"
+
+ sleep 1
+ secs=$(( secs - 1 ))
+done
+
+printf "\r${GREEN}DONE 00:00 100%%\n"
+notify-send "Timer" "$start_msg"
+paplay /usr/share/sounds/freedesktop/stereo/complete.oga >/dev/null 2>&1 || true
+