summaryrefslogtreecommitdiffstats
path: root/listimer
diff options
context:
space:
mode:
authorClément Sibille <clements@lisible.xyz>2026-02-07 14:14:46 +0100
committerClément Sibille <clements@lisible.xyz>2026-02-07 14:14:46 +0100
commitac0beeeafd5f9c28565c05e3ed718ac6c509d87c (patch)
tree5e6871b99be0e46428f3792f1fb30fcb0306971d /listimer
Initial commit
Diffstat (limited to 'listimer')
-rwxr-xr-xlistimer58
1 files changed, 58 insertions, 0 deletions
diff --git a/listimer b/listimer
new file mode 100755
index 0000000..fe5f4c3
--- /dev/null
+++ b/listimer
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+COMMAND=$1
+case "$COMMAND"
+in
+ "start")
+ if [ "$#" -ne 2 ]; then
+ echo "Usage: listimer start <minutes>";
+ exit 1;
+ fi
+ DURATION_MIN=$2
+ CURRENT_TIME=$(date +%s)
+ echo "$CURRENT_TIME\n\n$DURATION_MIN" > /tmp/listimer
+ ;;
+
+ "restart")
+ if [ "$#" -ne 1 ]; then
+ echo "Usage: listimer restart";
+ exit 1;
+ fi
+ CURRENT_TIME=$(date +%s)
+ sed -i "1s/.*/$CURRENT_TIME/" /tmp/listimer
+ ;;
+
+ "stop")
+ if [ "$#" -ne 1 ]; then
+ echo "Usage: listimer stop";
+ exit 1;
+ fi
+ CURRENT_TIME=$(date +%s)
+ rm /tmp/listimer
+ ;;
+
+ "query")
+ if [ ! -f /tmp/listimer ]; then
+ echo "No timer"
+ exit 0;
+ fi
+
+ START_TIME=$(sed -n '1p' < /tmp/listimer)
+ DURATION_MIN=$(sed -n '3p' < /tmp/listimer)
+ DURATION_SEC=$DURATION_MIN*60
+ CURRENT_TIME=$(date +%s)
+
+ ELAPSED_TIME_SEC=$(($CURRENT_TIME-$START_TIME))
+ ELAPSED_TIME_MIN=$(($ELAPSED_TIME_SEC/60))
+ REMAINING_TIME_MIN=$(($DURATION_MIN-$ELAPSED_TIME_MIN))
+
+ if [ "$REMAINING_TIME_MIN" -lt "$(($DURATION_MIN / 2))" ]; then
+ echo "<span weight=\"bold\" size=\"larger\" background=\"#FF0000\">$REMAINING_TIME_MIN minutes</span>"
+ elif [ "$REMAINING_TIME_MIN" -lt "0" ]; then
+ echo "TIME OUT!"
+ else
+ echo "$REMAINING_TIME_MIN minutes"
+ fi
+ ;;
+ *) echo "Unexpected command."
+esac
Go back to lisible.xyz