Hannikainen's blog

Snippet: livereloading anything



This small wrapper around fswatch/inotifywait runs the command in first argument every time any files change, without having to create project-specific watchers.

Examples:

#!/bin/sh

# Usage: live "echo edited file" file1 file2...

trap "exit" INT

command=""

if echo `uname` | grep -q Darwin; then
    command="fswatch -1 "
else
    command="inotifywait -qqe modify "
fi

act=$1

shift

while $($command $*) || true; do
    sh -c "$act";
done