Last active
March 25, 2021 21:10
-
-
Save lmas/ac50a40dcaaf4311e019 to your computer and use it in GitHub Desktop.
rerun - Simple script to rerun a command when files in the current directory has been modified
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 | |
COMMAND=$@ | |
DIR=$PWD | |
function block_for_change { | |
inotifywait -q -q -r -e modify $DIR | |
} | |
function kill_command { | |
# TODO BUG: When $COMMAND contains special regexp chars, like (), pgrep will | |
# fail to find the command in the process tree. | |
pid=$(pgrep -xf "$COMMAND") | |
if [ "$pid" ]; then | |
kill -s SIGKILL -$pid | |
fi | |
} | |
function run_command { | |
setsid $COMMAND & | |
} | |
trap kill_command INT | |
echo -e ">> Watching for file changes in current directory, press Ctrl+C to stop.\n" | |
run_command | |
while block_for_change; do | |
kill_command | |
run_command | |
echo -e "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This old, dirty thing is too buggy and shit! Discontinued.
Go see this new version that works waayy better.