Created
December 15, 2023 13:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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