dotfiles/system/bin/watch.sh
Severin Kaderli 0d3fdb8737 Fix shellcheck problems
Signed-off-by: Severin Kaderli <severin.kaderli@gmail.com>
2018-12-19 23:08:51 +01:00

30 lines
No EOL
549 B
Bash
Executable file

#!/bin/bash
#
# SCRIPT NAME:
# watch.sh
#
# AUTHOR:
# Severin Kaderli <severin.kaderli@gmail.com>
#
# DESCRIPTION:
# This script watches a file for changes and if it changes it
# executes the given command.
#
# USAGE:
# ./watch.sh FILE COMMAND...
. utils.sh
# The file to watch
FILE="${1}"
FILENAME=$(basename "${FILE}")
# The rest of the arguments is the command
shift
COMMAND="${*}"
print_header "Watching ${FILE}"
while inotifywait -qq -e close_write "${FILE}";
do
print_log "${FILENAME} has changed" "Executing command"
$COMMAND
done