Last active
September 29, 2025 15:35
-
-
Save mpapi/4656389 to your computer and use it in GitHub Desktop.
Revisions
-
mpapi revised this gist
Jan 28, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,4 +22,4 @@ COMMAND="$2" inotifywait -q --format '%f' -m -r -e close_write . \ | grep --line-buffered $PATTERN \ | xargs -I{} -r sh -c "echo [\$(date -Is)] $COMMAND && $COMMAND" -
mpapi created this gist
Jan 28, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/bin/sh # # Usage: whenever.sh [pattern] [command] # # Executes a command whenever files matching the pattern are closed in write # mode. "{}" in the command is replaced with the matching filename (via xargs). # Requires inotifywait from inotify-tools. # # For example, # # whenever.sh '\.md$' 'markdown -f $(basename {} .md).html {}' # # This runs "markdown -f my-document.html my-document.md" whenever # my-document.md is saved. # set -e -u PATTERN="$1" COMMAND="$2" inotifywait -q --format '%f' -m -r -e close_write . \ | grep --line-buffered $PATTERN \ | xargs -I{} -r sh -c "echo [$(date -Is)] $COMMAND && $COMMAND"