diff options
Diffstat (limited to 'xalarm')
| -rwxr-xr-x | xalarm | 67 | 
1 files changed, 55 insertions, 12 deletions
@@ -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  | 
