trap
#14
Replies: 1 comment
-
|
Great suggestion, and thanks to it I now have a better understanding of trap and exit codes. Ended up with this, cleanup() {
echo "" > /tmp/timericon;
pkill -RTMIN+3 dwmblocks;
exit 0
}
timer () {
trap cleanup SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM # 1 2 3 6 15
while [ $TOTAL_SECONDS -gt 0 ]; do
MIN=$(printf "%02d" $((TOTAL_SECONDS / 60)))
SEC=$(printf "%02d" $((TOTAL_SECONDS % 60)))
echo " $MIN $SEC " > /tmp/timericon;
pkill -RTMIN+3 dwmblocks;
sleep 1
((TOTAL_SECONDS--))
done
notify-send "Timer ended, take a break"
cleanup
}Much appreciated! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In dmenu_timer, the trap is in the wrong place, in my opinion. You should put it before the loop ✌️
Like this:
I'd put the ending into the cleanup function (followed by an 'exit', and just call it (even if a signal arrives, or the loop ends)... as long as you don't care about correct exit codes :D
Absolute overkill version:
Bonus idea, you can save the PID like 'echo "$$" > /tmp/timerpid', then you can stop the timer anytime with 'kill -HUP $(cat /tmp/timerpid). Of course you should 'rm' this file in cleanup()
3.7.5 Exit Status
trap(1p)
Beta Was this translation helpful? Give feedback.
All reactions