dotfiles/system/.local/bin/watch-file
Severin Kaderli 348ece6f11
Change email in all files
Signed-off-by: Severin Kaderli <severin@kaderli.dev>
2019-03-07 17:27:17 +01:00

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