diff --git a/kitsune b/kitsune index a47bada..7c04656 100755 --- a/kitsune +++ b/kitsune @@ -1,6 +1,8 @@ #!/usr/bin/python3 +import argparse import datetime +import fnmatch import os import sys import stat @@ -23,7 +25,7 @@ def watch(args): watched_dirs = [] watched_files = {} filename_length = 0 - for a in args: + for a in args.files: st = os.stat(a) if stat.S_ISDIR(st.st_mode): watched_dirs.append(a) @@ -43,10 +45,11 @@ def watch(args): last_ts = st.st_mtime_ns for de in os.scandir(d): if de.is_file(): - if de.path not in watched_files: - watched_files[de.path] = WatchedFile(de.path) - if len(de.path) > filename_length: - filename_length = len(de.path) + if args.match_filename is None or fnmatch.fnmatch(de.name, args.match_filename): + if de.path not in watched_files: + watched_files[de.path] = WatchedFile(de.path) + if len(de.path) > filename_length: + filename_length = len(de.path) # has any of the files changed for f in watched_files.values(): @@ -72,6 +75,9 @@ def watch(args): time.sleep(0.1) if __name__ == "__main__": - args = sys.argv[1:] if len(sys.argv) > 1 else ["."] + ap = argparse.ArgumentParser() + ap.add_argument("--match-filename") + ap.add_argument("files", nargs="*", default=["."]) + args = ap.parse_args() watch(args)