From 10bd517b3889405a1ec836d5416f421b285ebbed Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 4 Jun 2022 17:27:10 -0300 Subject: Feat: utils-x11: timedef: accepts both sleep(1) and date(1) formats --- xalarm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xalarm b/xalarm index 157aca1..399e4e6 100755 --- 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 } -- cgit v1.2.3