#!/bin/sh
#
# ---
# source: https://github.com/itchyny/bin

set -eu

file="$1"
shift
# commands=("$@")
commands="${commands}$*"
oldtime=0
while true; do
  newtime=$(perl -MPOSIX -le 'print strftime "%s", localtime((lstat)[9]) for @ARGV' "${file}")
  if [ "${oldtime}" != "0" ] && [ "${newtime}" != "${oldtime}" ]; then
    # eval "${commands[*]}"
    eval "${commands}"
  fi
  oldtime=${newtime}
  sleep 3
done
