dotter

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

watcher (643B)


      1 #!/bin/sh
      2 
      3 kill_viewer()
      4 {
      5 	kill $TPID
      6 	exit
      7 }
      8 
      9 die()
     10 {
     11 	echo $@
     12 	exit 1
     13 }
     14 
     15 requires()
     16 {
     17 	which "$1" > /dev/null || die "$1 could not be found"
     18 }
     19 
     20 requires xdotool
     21 requires dot
     22 requires inotifywait
     23 
     24 exec 0<&-
     25 SOURCE="${1:?"SOURCE required as 1st arg"}"
     26 VIEWER="${2:?"VIEWER required as 2nd arg"}"
     27 SCRIPT="${3:?"SCRIPT required as 3rd arg"}"
     28 TPID=""
     29 
     30 trap kill_viewer HUP INT
     31 
     32 while true
     33 do
     34 	FOCUS=$(xdotool getwindowfocus -f)
     35 	echo focus on $FOCUS
     36 	if test -e "$SOURCE"
     37 	then
     38 		$SCRIPT "${SOURCE}" | dot -Tpdf | $VIEWER &
     39 		TPID=$!
     40 		xdotool sleep 0.2 windowfocus --sync $FOCUS
     41 		inotifywait "${SOURCE}"
     42 		kill $TPID
     43 	else
     44 		sleep 1s
     45 	fi
     46 done