dotfiles/system/bin/watch.sh
Severin Kaderli a02e32523d Update dunstrc and watch.sh
Signed-off-by: Severin Kaderli <severin.kaderli@gmail.com>
2018-12-19 23:06:04 +01:00

30 lines
No EOL
552 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