diff options
Diffstat (limited to 'xalarm')
-rwxr-xr-x | xalarm | 63 |
1 files changed, 54 insertions, 9 deletions
@@ -23,18 +23,30 @@ function xalarm_set { #echo "xmessage $MESSAGE" | at now +$DELAY # Sleep implementation - sleep $DELAY - if which sm &> /dev/null; then - #sm -f '#ffffff' -b '#1c1c1c' $MESSAGE - (count=0; while sleep 1; do let count++; echo $MESSAGE - $count; echo -e '\f'; done) | sm -f '#ffffff' -b '#1c1c1c' - + # + # We put sleep into background and tell bash to wait it + # This way we can grab sleep PID and then be able to reset the timer if needed + sleep $DELAY & + SLEEP_PID="$!" + wait + + if [ "$ALARM_RESET" == "1" ]; then + ALARM_RESET=0 + echo "Resetting alarm..." + xalarm_set $DELAY $MESSAGE else - xmessage $MESSAGE + if which sm &> /dev/null; then + #sm -f '#ffffff' -b '#1c1c1c' $MESSAGE + (timer=0; while sleep 1; do let timer++; echo $MESSAGE - $timer; echo -e '\f'; done) | sm -f '#ffffff' -b '#1c1c1c' - + else + xmessage $MESSAGE + fi fi } # List alarms function xalarm_list { - ps -U $USER -o pid,state,lstart,command | grep xalarm | grep -v grep | grep -v list | grep -v cancel | grep -v pause | grep -v resume | \ + ps -U $USER -o pid,state,lstart,command | grep xalarm | grep -v grep | grep -v list | grep -v cancel | grep -v pause | grep -v resume | grep -v reset | grep -v reset-loop | \ sed -e "s|$FULLNAME||" -e "s|/bin/bash||" | grep -v -- "sed -e" } @@ -70,12 +82,41 @@ function xalarm_resume { done } +# Reset alarms +function xalarm_reset { + for pid in `xalarm_pids $1`; do + kill -USR1 $pid + done +} + +# Reset alarm loop counter +function xalarm_reset_loop { + for pid in `xalarm_pids $1`; do + kill -USR2 $pid + done +} + # Usage function xalarm_usage { echo "usage: $BASENAME [list|cancel|kill|help|usage|loop] [timedef] [message]" exit 1 } +# Respond to SIGUSR1 +function xalarm_sigusr1 { + ALARM_RESET="1" + kill $SLEEP_PID 2> /dev/null +} + +# Respond to SIGUSR2 +function xalarm_sigusr2 { + COUNT=0 +} + +# Register traps +trap xalarm_sigusr1 SIGUSR1 +trap xalarm_sigusr2 SIGUSR2 + # Dispatch if [ "$1" == "list" ]; then xalarm_list @@ -85,15 +126,19 @@ elif [ "$1" == "pause" ]; then xalarm_pause $2 elif [ "$1" == "resume" ]; then xalarm_resume $2 +elif [ "$1" == "reset" ]; then + xalarm_reset $2 +elif [ "$1" == "reset-loop" ]; then + xalarm_reset_loop $2 elif [ "$1" == "help" ] || [ "$1" == "usage" ]; then xalarm_usage elif [ "$1" == "loop" ]; then - count="0" + COUNT="0" shift while true; do - let count++ - xalarm_set $* $count + let COUNT++ + xalarm_set $* $COUNT done else xalarm_set $* |