Pieds-Nus_custom-scripts/xpause
Pieds-Nus 938bd641a2 Minor update, some new scripts, some updated
sss: save some space, picture compressor
pdfdiff : perform a visual diff on simila pdfs to highlight
2025-02-27 21:40:47 +00:00

43 lines
971 B
Bash

#!/bin/bash
#Usage
# xpause [resume]
# Click on a window to pause its process, or resume all such paused processes
#return status:
# 0 - Ok
# 1 - kill failed
# 2 - no pid found to resume
# 3 - failed to get pid from window
if test "$1" = "resume" ; then
if test -s /tmp/xpause ; then
kill -SIGCONT $(cat /tmp/xpause) || ( echo "xpause FAILED (kill)" ; exit 1 )
echo "xunpaused $(cat /tmp/xpause | wc -l)"
rm /tmp/xpause
exit 0
fi
echo "xpause FAILED" "No process to resume"
exit 2
fi
pid=$(xprop | grep PID | cut -d "=" -f 2)
test "$pid" -gt 0 || ( echo "xpause failed to get pid from window" ; exit 3 )
if test -s /tmp/xpause ; then
if grep "$pid" /tmp/xpause ; then
if kill -SIGCONT "$pid" ; then
echo "unpaused $pid"
exit 0
else
echo "xunpause FAILED (kill -SIGCONT \"$pid\")"
exit 1
fi
fi
fi
echo $pid >> /tmp/xpause
kill -s "SIGSTOP" $pid || ( echo "xpause FAILED (kill - SIGSTOP $pid)" ; exit 1 )
echo "xpaused $pid"
exit 0