Skip to content

Instantly share code, notes, and snippets.

@michitux
Created March 1, 2013 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michitux/5064086 to your computer and use it in GitHub Desktop.
Save michitux/5064086 to your computer and use it in GitHub Desktop.
Simple script for executing a command whenever a file in the current directory (or a subdirectory of it) that matches a certain expression (using grep) is changed. The script uses inotifywait (from inotify-tools), i.e. it waits efficiently using inotify. The rationale for watching the whole directory is that editors like VIM work with temporary …
#!/bin/bash
command="$1"
expression="$2"
$command
inotifywait -r -m --format '%f' -e close_write "$PWD" | while read file; do
if echo "$file" | grep "$expression"; then
$command
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment