Inotify, Run (Python) script once it changes

This is sadly Linux Only, start by installing inotify-tools:

# apt-get install inotify-tools

and create the following script:

#!/bin/sh
clear
echo Waiting for filechange ...
inotifywait -q -m -e close_write,moved_to --format %e/%f . |
while IFS=/ read -r events file; do
    if [ "$file" = "script.py" ]; then
        clear
        python ./script.py
    fi
done

this actually watches the directory, because Vim writes files by writing your alterations to a temporary file and moving it in place of the old one, however this aproach also works with normal write.

Dette indlæg blev udgivet i Linux, Vim. Bogmærk permalinket.

Skriv et svar