#!python
from __future__ import print_function
import sys
from os import path

from inotify import adapters, constants
import six


def wait_for_dir(watched_path):
    watched_path = six.binary_type(watched_path.encode('utf-8'))
    i = adapters.InotifyTree(watched_path, mask=constants.IN_CLOSE_WRITE)
    for event in i.event_gen():
        if event is not None:
            filename = path.basename(event[3])
            dir_name = event[2]
            if filename.startswith(b'.#') or filename.startswith(b'flycheck') or filename.endswith(b"~"):
                continue
            elif dir_name.endswith(b'.cache/v/cache'):
                continue
            else:
                print(event)
                sys.exit(0)


if __name__ == '__main__':
    wait_for_dir(sys.argv[1])

@@ -1,12 +1,27 @@
 #!
+/usr/bin/env 
 python
+3%0A
 %0Afro
@@ -175,16 +175,18 @@
 th):%0A   
+ #
  watched
@@ -489,17 +489,16 @@
 rtswith(
-b
 '.#') or
@@ -518,17 +518,16 @@
 rtswith(
-b
 'flychec
@@ -551,17 +551,16 @@
 ndswith(
-b
 %22~%22):%0A  
@@ -617,17 +617,16 @@
 ndswith(
-b
 '.cache/

update iwatch.py for python3