spock
8/1/2017 - 8:21 PM

Watch file change script

Execute python script on file change in a directory. Useful when coding to instantly get output from the modified code.

Setup:

  1. Install inotify: sudo apt-get install inotify-tools
  2. Make script executable chmod +x pywatch.sh
  3. Make script globally available. You can find explanation elsewhere.

Usage: Watch python directory like this: pywatch.sh run_this.py

Now any time a file modification inside a directory is saved run_this.py is executed.

#!/bin/bash

echo watch activated
inotifywait -qmre modify . | while read f

do
    python $1
done