Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore files starting with a period using watchmedo?

My file editor creates temporary files prefixed with a ..

I am running:

watchmedo shell-command -p '*.py' -R -c 'echo "${watch_src_path}"'

I see events for the temporary files as I am editing, then two events on file save (presumably because it does a delete and write).

I would like to see one event -- only when I save a file.

Is there a way for me to do this with just the CLI? I am not interested in creating a python script and using the watchdog API directly.

like image 703
ToBeReplaced Avatar asked Dec 10 '25 23:12

ToBeReplaced


1 Answers

Use the --ignore-patterns (-i) switch.

watchmedo shell-command \
    -p'*.py' \
    -R \
    -c'echo "${watch_src_path}"'\
    --ignore-patterns="*/.*"

Note that watchmedo is matching on the full watch_src_path so your ignore pattern can't be as simple as ".*" like you'd think at first. Also all the pitfalls of wildcards are in effect, so if you were doing something silly like working in a hidden directory /path/to/some/.hidden/dir then you'd have to have a fancier pattern.

You also might want the --ignore-directories (-D) switch if the directory-related event is causing you annoyance too (this one is just boolean, no argument needed).

like image 76
ben author Avatar answered Dec 12 '25 11:12

ben author



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!