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

Improve filtering by filetype (exclude a filetype, or allow multiple filetypes to be specified) #177

Closed
rlue opened this issue Nov 22, 2017 · 3 comments
Milestone

Comments

@rlue
Copy link
Contributor

rlue commented Nov 22, 2017

Currently, fd offers the -t command line option to view only files of a single type (regular files, directories, symbolic links).

However, there is no way (that I can see) to view all files except those of a single type (in other words, to exclude a given filetype from the results). Perhaps a syntax like +td or -Td to exclude directories, or -tfl to do the same?

Hopefully, I've missed something, and this feature is already available!

Workaround

The best I can think to do is

$ rg -FNxvf <(fd -td) <(fd)
  • rg <(fd) searches the output of fd
  • -f <(fd -td) searches against patterns contained in the "file" <(fd -td) (the output of that command), rather than patterns given on the command line
  • -F treats search patterns as fixed strings (not regular expressions)
  • -x requires a whole like match (like wrapping each line in ^$)
  • -v inverts the results (gives non-matches, rather than matches).
  • -N suppresses line numbers
@sharkdp
Copy link
Owner

sharkdp commented Nov 22, 2017

Thank you very much for your feedback.

Hopefully, I've missed something, and this feature is already available!

Unfortunately - no. However, consider the following:

▶ tree
.
├── dir
├── file
├── symlink_to_dir -> dir
└── symlink_to_file -> file
  • We can search for dir only (-td)
  • We can search for file only (-tf`)
  • We can search for both symlinks (-tl)
  • We can also search for dir and symlink_to_dir (-L -td)
  • as well as for file and symlink_to_file (-L -tf)

What is missing is:

  1. search for dir and both symlinks
  2. search for file and both symlinks
  3. search for dir and file

For now, I would propose to allow for multiple occurrences of the --type/-t option in a union-like fashion ("or" instead of "and"). Since there are only three types of entries, I think this would still be acceptable (having to specify --type file --type directory instead of --exclude-type symlink).

I'm open for other ideas, though. What do you think?

@septatrix
Copy link

For now, I would propose to allow for multiple occurrences of the --type/-t option in a union-like fashion ("or" instead of "and"). Since there are only three types of entries, I think this would still be acceptable (having to specify --type file --type directory instead of --exclude-type symlink).

Now there are 7+2 file types (the latter two being the executable and empty dir). A negated filetype seems like a reasonable addition now. Should I create a new issue for that?

@tavianator
Copy link
Collaborator

A negated filetype seems like a reasonable addition now. Should I create a new issue for that?

There is already #632

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

No branches or pull requests

4 participants