Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
swatch
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
NORMAL=$(tput sgr0)
swatch() {
[ -a /tmp/swatch ] || touch /tmp/swatch
inotifywait -m -e close_write,moved_to --format %e/%f -r /tmp/swatch |
{ echo "hi" ; while IFS=/ read -r events file; do
echo "$file $events"
done } | while read i
do
printf "exec @$(date "+%H:%M:%S") \n"
printf "'%s' " "$@"
evalthenblink "$@" &
done
}
evalthenblink() {
eval "$@"
res="$?"
if [ "$res" == "0" ]; then
printf "${GREEN}${res}${NORMAL}\n"
else
printf "${RED}${res}${NORMAL}\n"
fi
# This is used to blink the blink-1-tool, use anything else
b "$res"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment