facebookincubator / fastmod

A fast partial replacement for the codemod tool
Apache License 2.0
1.66k stars 41 forks source link

excluding a directory from being searched #11

Closed asmallteapot closed 6 years ago

asmallteapot commented 6 years ago

Hi there! Is there a way to exclude a subdirectory from being searched, like ack's --ignore-dir= option?

swolchok commented 6 years ago

You can do this with the --glob option. It plumbs into the ignore crate's glob support, which is documented to "have precisely the same semantics as a single line in a gitignore file, where the meaning of ! is inverted: namely, ! at the beginning of a glob will ignore a file". gitignore documentation says that putting a slash at the end of a pattern makes it match only directory names, so:

$ cd /tmp
$ mkdir fmtest
$ cd fmtest
$ ls
$ mkdir yes
$ mkdir no
$ yes/a.txt
$ no/a.txt
$ fastmod hello goodbye -g '!no/'
./yes/a.txt:1
- hello
+ goodbye

Accept change (y = yes [default], n = no, e = edit, A = yes to all, E = yes+edit, q = quit)?
n
$ mkdir subdir
$ mv no yes subdir
$ fastmod hello goodbye -g '!no/'
./subdir/yes/a.txt:1
- hello
+ goodbye

Accept change (y = yes [default], n = no, e = edit, A = yes to all, E = yes+edit, q = quit)?
n

Hope this helps!

asmallteapot commented 6 years ago

This is perfect, thanks! I had no idea glob syntax supported negation, this is life-changing tbh