30 lines
No EOL
556 B
Bash
Executable file
30 lines
No EOL
556 B
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# SCRIPT NAME:
|
|
# watch-file
|
|
#
|
|
# AUTHOR:
|
|
# Severin Kaderli <severin@kaderli.dev>
|
|
#
|
|
# DESCRIPTION:
|
|
# This script watches a file for changes and if it changes it
|
|
# executes the given command.
|
|
#
|
|
# USAGE:
|
|
# ./watch-file FILE COMMAND...
|
|
. utils
|
|
|
|
# The file to watch
|
|
FILE="${1}"
|
|
FILENAME=$(basename "${FILE}")
|
|
|
|
# The rest of the arguments is the command
|
|
shift
|
|
COMMAND="${*}"
|
|
|
|
print_section "Watching ${FILE}"
|
|
while inotifywait -qq -e close_write "${FILE}";
|
|
do
|
|
print_notify "${FILENAME} has changed" "Executing command"
|
|
$COMMAND
|
|
done |