dotter

graphiz helpers
git clone git://deadbeef.fr/dotter.git
Log | Files | Refs | README | LICENSE

watcher (520B)


      1 #!/bin/sh
      2 
      3 kill_viewer()
      4 {
      5 	kill $TPID
      6 	exit
      7 }
      8 
      9 which inotifywait || exit
     10 exec 0<&-
     11 SOURCE="${1:?"SOURCE required as 1st arg"}"
     12 VIEWER="${2:?"VIEWER required as 2nd arg"}"
     13 SCRIPT="${3:?"SCRIPT required as 3rd arg"}"
     14 TPID=""
     15 
     16 trap kill_viewer HUP INT
     17 
     18 while true
     19 do
     20 	FOCUS=$(xdotool getwindowfocus -f)
     21 	echo focus on $FOCUS
     22 	if test -e "$SOURCE"
     23 	then
     24 		./$SCRIPT "${SOURCE}" | dot -Tpdf | $VIEWER &
     25 		TPID=$!
     26 		xdotool sleep 0.1 windowfocus --sync $FOCUS
     27 		inotifywait "${SOURCE}"
     28 		kill $TPID
     29 	else
     30 		sleep 1s
     31 	fi
     32 done