Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a thing like --and, --or or --not? #714

Closed
x3rAx opened this issue Jan 8, 2021 · 7 comments
Closed

Is there a thing like --and, --or or --not? #714

x3rAx opened this issue Jan 8, 2021 · 7 comments
Labels

Comments

@x3rAx
Copy link

x3rAx commented Jan 8, 2021

I would like to combine queries like so:

fd --type symlink --and --owner --not root

or

fd --type symlink --or --type file

Is this somehow possible with fd?

@x3rAx x3rAx added the question label Jan 8, 2021
@x3rAx x3rAx changed the title Is there a thing like --and or --or? Is there a thing like --and, --or or --not? Jan 8, 2021
@x3rAx
Copy link
Author

x3rAx commented Jan 8, 2021

Ok, I just found fd --help (I used fd -h before which gave me a shortened help page).

So I found some things that work but they are not as consistent as I would wish:

It seems like fd automatically uses and or or based on what "makes sense".

For example

fd --type symlink --owner root

is treated like an and whereas

fd --type symlink --type file

is treated like an or. This does not mean that using the same option twice is always treated like or:

fd --type directory --type file --type executable

is treated like (directory OR file) AND executable (only executable files and directories with the executable bit set are found).

I also found that searching files that are not owned by a specific user is possible using

fd --owner \!root

(or with quotes fd --owner '!root').

This is nice, however, there seems to be no not for the file type:

fd --type \!symlink

gave an error:

error: '!symlink' isn't a valid value for '--type <filetype>...'
        [possible values: d, directory, e, empty, executable, f, file, l, p, pipe, s, socket, symlink, x]

(it should however be possible to use fd -t directory -t file -t symlink -t pipe -t socket to get the same results, but I'm not sure if there is something missing)

So the question remains:

Is there a way to explicitly combine options with and, or or not?

@sharkdp
Copy link
Owner

sharkdp commented Feb 15, 2021

I would like to combine queries like so:

fd --type symlink --and --owner --not root

You can do this by running

fd --type symlink --owner '!root'

Different filters (type/owner/size/…) are combined using AND.

or

fd --type symlink --or --type file

You can do this by running

fd --type symlink --type file

Multiple filters of the same kind are combined using OR.

Ok, I just found fd --help (I used fd -h before which gave me a shortened help page).

There is a note at the end of the short fd -h help text: "fd -h prints a short and concise overview while fd --help gives all details.". Do you think it should be put somewhere else to make it better visible? You seem to have missed it, and you are probably not the only one.

It seems like fd automatically uses and or or based on what "makes sense".

Yes.

This does not mean that using the same option twice is always treated like or:

fd --type directory --type file --type executable

is treated like (directory OR file) AND executable (only executable files and directories with the executable bit set are found).

You are right. executable and empty are special in that they mean: only show executable/empty results. Otherwise --type file --type empty would mean: "show me files OR empty directories/files", which would result in ALL files and empty directories. I don't think that's what most users would expect. See also: #246 (comment)

If you think that the behavior is confusing, please let us know!

If you think it could be better documented (it certainly can be), please let us know was well (see also: #695).

there seems to be no not for the file type:

fd --type \!symlink

Right. Maybe we should add that for consistency. It would be great if you could open a separate feature request ticket for that.

(it should however be possible to use fd -t directory -t file -t symlink -t pipe -t socket to get the same results, but I'm not sure if there is something missing)

Yeah, that's not ideal

So the question remains:

Is there a way to explicitly combine options with and, or or not?

There is no way to do this, and probably never will be. See discussion here: #560 (comment). What are some actual (real world) use cases that are not supported right now?

Concerning not, see also: #595

@x3rAx
Copy link
Author

x3rAx commented Mar 24, 2021

Thank you for your answers 🙂

Ok, I just found fd --help (I used fd -h before which gave me a shortened help page).

There is a note at the end of the short fd -h help text: "fd -h prints a short and concise overview while fd --help gives all details.". Do you think it should be put somewhere else to make it better visible? You seem to have missed it, and you are probably not the only one.

I think it might help if in addition to the "Note", the -h help text differentiated between -h and --help. Currently it combines these both like so:

    -h, --help              Prints help information

Maybe it would be more obvious while scanning the help text if it was at the beginning of the FLAGS: section and and split like this:

    -h                      Prints a short and concise overview
        --help              Prints detailed help information

It might also help to start the note with "Use" or "You can" to indicate with the first word(s), that the user can do something here:

Note: Use `fd --help` to get detailed help information. `fd -h` only prints a short an concise overview.
Note: You can use `fd --help` to get detailed help information. `fd -h` only prints a short an concise overview.

Maybe also colorize "Note" and "--help" to make it more prominent.

I've tried splitting -h and --help and clap allows it. I also colorized the note. I'll send a PR in a minute.

@icher
Copy link

icher commented Oct 20, 2021

So, if I want to find files with "foo" OR "bar":

fd "foo|bar"

How can I find files with "foo" AND "bar"?

@tmccombs
Copy link
Collaborator

Technically possible with: fd 'foo.*bar|bar.*foo', but that isn't really very ergonomic. And doesn't scale well at all.

@icher
Copy link

icher commented Oct 20, 2021

Technically possible with: fd 'foo.*bar|bar.*foo', but that isn't really very ergonomic. And doesn't scale well at all.

So.. if we speaking practically it's not possible for now?

@sharkdp
Copy link
Owner

sharkdp commented Nov 14, 2021

Closing this in favor of #315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants