dotool/dotoold

30 lines
678 B
Text
Raw Permalink Normal View History

2022-10-20 15:21:20 +02:00
#!/bin/sh
2023-08-15 13:53:04 +02:00
for a; do
case "$a" in
-h|--help)
echo 'dotoold runs dotool reading from a pipe for dotoolc to write to. dotoold
2023-05-11 12:16:22 +02:00
will exit immediately if the pipe is already being read. The path used
for the pipe is $DOTOOL_PIPE else /tmp/dotool-pipe.' >&2
2023-08-15 13:53:04 +02:00
exit
;;
--) break;;
esac
done
2022-10-20 15:21:20 +02:00
fifo_being_read(){
[ -p "$1" ] && /bin/echo 1<>"$1" >"$1"
}
2023-04-28 17:44:54 +02:00
p="${DOTOOL_PIPE:-/tmp/dotool-pipe}"
2022-10-20 15:21:20 +02:00
if fifo_being_read "$p" 2> /dev/null; then
2023-01-25 18:47:12 +01:00
printf %s\\n "dotoold: another instance is already reading the pipe: $p" >&2
2022-10-20 15:21:20 +02:00
exit 1
fi
2023-01-25 18:08:23 +01:00
rm -f -- "$p" || exit 1
trap 'rm -f -- "$p"; pkill -P $$; trap - EXIT; exit' EXIT INT TERM HUP
2022-10-20 15:21:20 +02:00
mkfifo -m 660 "$p" || exit 1
2023-08-15 13:53:04 +02:00
dotool "$@" <> "$p" &
wait $!