diff options
| author | Silvio Rhatto <rhatto@riseup.net> | 2018-03-14 09:43:40 -0300 | 
|---|---|---|
| committer | Silvio Rhatto <rhatto@riseup.net> | 2018-03-14 09:43:40 -0300 | 
| commit | cf015fcedd3fd0e71d2ea7fb0475f39ff4f20c62 (patch) | |
| tree | a467409c4438f94b51a89ad7b267276c3329bea3 /xalarm | |
| parent | 7b2fb7a022a3273177eefcd68f67c4a7bc3edbbb (diff) | |
| download | utils-x11-cf015fcedd3fd0e71d2ea7fb0475f39ff4f20c62.tar.gz utils-x11-cf015fcedd3fd0e71d2ea7fb0475f39ff4f20c62.tar.bz2  | |
Enhanced xalarm
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  | 
