Skip to content

Instantly share code, notes, and snippets.

@bazzargh
Created December 15, 2023 13:14
Show Gist options
  • Save bazzargh/411e91ed7196aca5941e520d75b14459 to your computer and use it in GitHub Desktop.
Save bazzargh/411e91ed7196aca5941e520d75b14459 to your computer and use it in GitHub Desktop.
for advent of code, run on save of .py or .txt data. Used as: tmux new -s aoc -n log aocwatch \; splitw -h
#!/bin/bash
echo Starting watch in $(pwd)
fswatch --event=Updated . | while read -r event; do
if [[ "$event" == *.py ]]; then
echo Setting script to ${event}. Data is ${data:-not set}
script=$event
elif [[ "$event" == *.txt ]]; then
echo Setting data to ${event}. Script is ${script:-not set}
data=$event;
else
echo "Skipping $event"
continue;
fi
if [[ -n $child ]]; then
echo Killing $child
kill -9 $child || echo no child running
fi
set -x
python3 ${script:-${data/%.txt/.py}} ${data:-${script/%.py/.txt}} & child=$!
set +x
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment