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:

Run ./clj-kondo.sh for every file change: $ live "clear && ./clj-kondo.sh | head -n 30" src/**/*.clj*

Re-render png every time source Graphviz file changes: $ live "dot map.dot -Tpng -o map.png" map.dot

#!/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
Copyright (c) 2024 Jaakko Hannikainen