This script opens the surf web browser associated with a .html file. After opening it will monitor for changes in the received path files and update the current page when any change is detected.
surf_monitor :file.html: :path_to_monitor:
You should have surf installed - download. And also the inotifywait from the inotify-tools.
First we will check the html file argument, then start the surf browser the first time, after that we start monitoring the received path files so we can update surf when any change occurs.
First we will start the surf browser associated with the received file. The process is put in background so we can continue to the next commands.
We need to make sure that we are really receiving some html file or the browser will not display anything, and we need to tell which files we want to monitor. So we check if at least two arguments were received, and if it wasn't we finish the program by printing the expected usage.
if [ $# -lt 2 ]; then echo "Usage: $0 :file.html: :path_to_monitor:" exit 1 fi
Used in section 4
We know we received some file and the surf browser is running, so now we will start monitoring for changes in the path to monitor. Since the path already needs to exist we can monitor only the modification event.
After the event is detected we want to update the currenly displayed web page. Surf allows us to tell it to refresh the open webpage using the SIGHUP signal. To be able to send that signal to the surf browser we need to have it's pid.
And then we can send the signal to the surf proccess.