]> gitweb.fluxo.info Git - utils-x11.git/commitdiff
Feat: utils-x11: timedef: accepts both sleep(1) and date(1) formats
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 4 Jun 2022 20:27:10 +0000 (17:27 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 4 Jun 2022 20:27:10 +0000 (17:27 -0300)
xalarm

diff --git a/xalarm b/xalarm
index 157aca10fceed5f0515fc1b1adf7c546de0a69ef..399e4e6c93281ec1df5dc7a6799ba39baf6a69d2 100755 (executable)
--- a/xalarm
+++ b/xalarm
@@ -20,6 +20,18 @@ function xalarm_set {
   shift
   MESSAGE="${*:-Alarm!}"
 
+  # Suppor for HH:MM format
+  if echo $DELAY | grep -q '[0-9]:[0-9][0-9]'; then
+    NOW="`date +%s`"
+    LATER="`date -d $DELAY +%s`"
+    DELAY="$(($LATER - $NOW))"
+
+    if (($LATER < $NOW)); then
+      echo "$BASENAME: deadline must be later than now"
+      exit 1
+    fi
+  fi
+
   # AT(1) implementation
   # Example run: xalarm 1minute mymessage
   #echo "xmessage $MESSAGE" | at now +$DELAY
@@ -122,6 +134,8 @@ function xalarm_reset_loop {
 # Usage
 function xalarm_usage {
   echo "usage: $BASENAME [list|cancel|kill|resume|continue|help|usage|loop|reset|reset-loop] [timedef] [message]"
+  echo ""
+  echo "timedef: accepts both sleep(1) and date(1) formats"
   exit 1
 }