dotfiles/system/.local/bin/watch-file
Severin Kaderli 410d0b33c6
Rename scripts
Signed-off-by: Severin Kaderli <severin.kaderli@gmail.com>
2019-03-06 16:53:16 +01:00

30 lines
No EOL
562 B
Bash
Executable file

#!/usr/bin/env bash
#
# SCRIPT NAME:
# watch-file
#
# 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-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