Genivia / ugrep

NEW ugrep 6.5: a more powerful, ultra fast, user-friendly, compatible grep. Includes a TUI, Google-like Boolean search with AND/OR/NOT, fuzzy search, hexdumps, searches (nested) archives (zip, 7z, tar, pax, cpio), compressed files (gz, Z, bz2, lzma, xz, lz4, zstd, brotli), pdfs, docs, and more
https://ugrep.com
BSD 3-Clause "New" or "Revised" License
2.56k stars 109 forks source link

Restricting search to starting filesystem of all paths #349

Closed wavexx closed 6 months ago

wavexx commented 7 months ago

I'd like to always restrict the search to the filesystems of all paths which are given on the command line during interactive usage, as find -xdev does. As a common example:

ug pattern /var

should search inside the filesystem of /var, but exclude any other fs (such as a nested tmpfs). The --include-fs requires doubling all the arguments, which doesn't really work well with shell aliases or functions. For example, if I give two starting paths on two filesystems, it's generally implied I want both filesystems to be included:

ug pattern /fs1 /fs2

which would require --include-fs=/fs1,/fs2 or two extra args. The suggested --include-fs=. is not really a good substitute for this behavior, since very often $CWD has nothing to do with the searched paths.

genivia-inc commented 7 months ago

Yes, I agree that this is a valid use case to only recursively search the specified targets without descending into other FS. Like find -x, this is something we can do.

The only question is whether we need yet another long option for this. Because we have two related options --include-fs= and --exclude-fs= we may want to use one of them for this feature, for example when no mount argument is specified. So perhaps --exclude-fs without an argument is suitable for this feature? Since find -x or find -xdev pronounce as "ex", it might be a reasonable choice?

wavexx commented 7 months ago

Seems reasonable, and I agree that avoiding another flag is a good thing™

genivia-inc commented 7 months ago

I've implemented the new feature in my dev version to try it out.

So you can use --exclude-fs or --exclude-fs= without MOUNT points.

For the help info and man page, I'm considering the following update:

    --exclude-fs=MOUNTS
            Exclude file systems specified by MOUNTS from recursive searches.
            MOUNTS is a comma-separated list of mount points or pathnames to
            directories.  When omitted, prevents descending into file systems
            that are not associated with the specified file and directory
            search targets.  Note that --exclude-fs=MOUNTS take priority over
            --include-fs=MOUNTS.  This option may be repeated.

As a minor point, I want to clarify that if no search targets are explicitly specified, then implicitly the search target is the working directory. In that case, only the FS associated with the working directory is searched.

Alternative wording:

    --exclude-fs=MOUNTS
            Exclude file systems specified by MOUNTS from recursive searches.
            MOUNTS is a comma-separated list of mount points or pathnames to
            directories.  When omitted, only descends into the file systems
            associated with the specified file and directory search targets.
            Note that --exclude-fs=MOUNTS take priority over
            --include-fs=MOUNTS.  This option may be repeated.

I like this a bit better. Less confusing. No double negation in a sentence.

To avoid breaking symmetry of these two options, a default --include-fs could be useful as a shorthand for --include-fs=.:

    --include-fs=MOUNTS
            Only file systems specified by MOUNTS are included in recursive
            searches.  MOUNTS is a comma-separated list of mount points or
            pathnames to directories.  When omitted, restricts recursive
            searches to the file system of the working directory only, same as
            --include-fs=. (dot). Note that --exclude-fs=MOUNTS take priority
            over --include-fs=MOUNTS.  This option may be repeated.
wavexx commented 7 months ago

As a minor point, I want to clarify that if no search targets are explicitly specified, then implicitly the search target is the working directory. In that case, only the FS associated with the working directory is searched.

Very good point!

genivia-inc commented 7 months ago

As a minor point, I want to clarify that if no search targets are explicitly specified, then implicitly the search target is the working directory. In that case, only the FS associated with the working directory is searched.

Very good point!

In that case it's the same as --include-fs=. because we're searching the working directory without descending into other devices. So there are two ways to get the same. But writing that in the man page would make it more confusing than it really is.

genivia-inc commented 6 months ago

Implemented.