Files
dandelion/watch.sh
2024-09-22 21:12:51 -07:00

25 lines
508 B
Bash
Executable File

#!/bin/bash
# Check if the correct number of arguments is passed
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <file_to_watch> <process_name> <command_to_run>"
exit 1
fi
# Assign arguments to variables
FILE_TO_WATCH=$1
PROCESS_NAME=$2
COMMAND_TO_RUN=$3
eval "$COMMAND_TO_RUN" &
# Watch the file for changes
while inotifywait -e modify "$FILE_TO_WATCH"; do
# Kill the process
sudo pkill "$PROCESS_NAME"
# Run the provided command (like build and run)
eval "$COMMAND_TO_RUN" &
done