aboutsummaryrefslogtreecommitdiff
path: root/xalarm
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2018-03-14 09:43:40 -0300
committerSilvio Rhatto <rhatto@riseup.net>2018-03-14 09:43:40 -0300
commitcf015fcedd3fd0e71d2ea7fb0475f39ff4f20c62 (patch)
treea467409c4438f94b51a89ad7b267276c3329bea3 /xalarm
parent7b2fb7a022a3273177eefcd68f67c4a7bc3edbbb (diff)
downloadutils-x11-cf015fcedd3fd0e71d2ea7fb0475f39ff4f20c62.tar.gz
utils-x11-cf015fcedd3fd0e71d2ea7fb0475f39ff4f20c62.tar.bz2
Enhanced xalarm
Diffstat (limited to 'xalarm')
-rwxr-xr-xxalarm67
1 files changed, 55 insertions, 12 deletions
diff --git a/xalarm b/xalarm
index 712ee65..c16132c 100755
--- a/xalarm
+++ b/xalarm
@@ -4,18 +4,61 @@
# See discussion at https://www.reddit.com/r/Gentoo/comments/1rryh1/kalarm_replacement/
#
-# Delay
-DELAY="${1:-10m}"
+# Parameters
+FULLNAME="$0"
+BASENAME="`basename $0`"
-# Message
-shift
-MESSAGE="${*:-Alarm!}"
+# List alarms
+function xalarm_list {
+ ps -U $USER -o pid,command | grep xalarm | grep -v grep | grep -v list | grep -v cancel | \
+ sed -e "s|$FULLNAME||" -e "s|/bin/bash||" | grep -v -- "sed -e"
+}
-# AT(1) implementation
-# Example run: xalarm 1minute mymessage
-#echo "xmessage $MESSAGE" | at now +$DELAY
+# Set alarm
+function xalarm_set {
+ # Delay
+ DELAY="${1:-10m}"
-# Sleep implementation
-# Example run: xalarm 1m mymessage
-sleep $DELAY
-xmessage $MESSAGE
+ # Message
+ shift
+ MESSAGE="${*:-Alarm!}"
+
+ # AT(1) implementation
+ # Example run: xalarm 1minute mymessage
+ #echo "xmessage $MESSAGE" | at now +$DELAY
+
+ # Sleep implementation
+ # Example run: xalarm 1m mymessage
+ sleep $DELAY
+ xmessage $MESSAGE
+}
+
+# Cancel alarms
+function xalarm_cancel {
+ if [ ! -z "$1" ]; then
+ if xalarm_list | awk '{ print $1 }' | grep -q "^$1"; then
+ kill $1
+ fi
+ else
+ for pid in `xalarm_list | awk '{ print $1 }'`; do
+ kill $pid
+ done
+ fi
+}
+
+# Usage
+function xalarm_usage {
+ echo "usage: $BASENAME [list|cancel|kill|help|usage] [timedef] [message]"
+ exit 1
+}
+
+# Dispatch
+if [ "$1" == "list" ]; then
+ xalarm_list
+elif [ "$1" == "cancel" ] || [ "$1" == "kill" ]; then
+ xalarm_cancel $2
+elif [ "$1" == "help" ] || [ "$1" == "usage" ]; then
+ xalarm_usage
+else
+ xalarm_set $*
+fi