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

Allow multiple PATTERNs #11

Open
tbm opened this issue May 16, 2024 · 8 comments
Open

Allow multiple PATTERNs #11

tbm opened this issue May 16, 2024 · 8 comments
Labels
enhancement New feature or request ux User experience, interface, and usability

Comments

@tbm
Copy link
Contributor

tbm commented May 16, 2024

Since you figure out PATTERN by certain characters (e.g. # for tag), it would be possible to specify multiple PATTERNs.

e.g. bean-grep 2024-05-01 "#foo" books/2024

@zacchiro zacchiro added the enhancement New feature or request label May 16, 2024
@zacchiro
Copy link
Owner

Agreed, makes sense (and would bring bean-grep closer to grep behavior).

@zacchiro
Copy link
Owner

Note that #9 and #11 together can make the parsing of arguments ambiguous.

@zacchiro zacchiro changed the title Allow multiple PATTERN Allow multiple PATTERNs May 18, 2024
@zacchiro
Copy link
Owner

zacchiro commented May 19, 2024

Now that #16 is done, implementing the semantics of this is trivial. However, the syntax problem remains: how to make it non-ambiguous and user-friendly? The main problem being that if one can provide multiple patterns and multiple files, it's not clear where the former stop and the latter begin.

(I've considered the possibility of testing for file existence to decide, but I fear that would be too smart not to be surprising, and can possibly backfire in weird cases.)

For reference, grep has a very weird way of supporting this, which I've never used myself, it says:

grep searches for PATTERNS in each FILE. PATTERNS is one or more patterns separated by newline characters

That would work for bean-grep too, and I'm not opposed to it, but it's quite clunky to use on the CLI.

@zacchiro zacchiro added help wanted Extra attention is needed ux User experience, interface, and usability labels May 19, 2024
@tbm
Copy link
Contributor Author

tbm commented May 20, 2024

One option would be to require one argument, so you'd have to quote it, e.g.

bean-grep "@foo #bar" books/2023 books/2024

@zacchiro
Copy link
Owner

That wouldn't work, because the last resort of pattern inference is -s/--somewhere which takes arbitrary strings that might legitimately contain spaces.

Yesterday, however, I've tried in practice the grep approach (patterns are newline-separated) and it is not that bad to type using double quotes as in your example:

bean-grep "@foo
bar baz
#qux" books/2023 books/2024

because shells (I've tried both bash and zsh) does not complain when they see a newline after a non-closed quoted string.

So the above appears to be a viable option, what do you think?

@tbm
Copy link
Contributor Author

tbm commented May 20, 2024

I guess, yes. I'm not really the best person to ask, though.

zacchiro added a commit that referenced this issue May 23, 2024
nothing else is actually implemented...

Related #11
@zacchiro zacchiro removed the help wanted Extra attention is needed label May 23, 2024
zacchiro added a commit that referenced this issue May 25, 2024
nothing else is actually implemented...

Related #11
zacchiro added a commit that referenced this issue May 25, 2024
@Goorzhel
Copy link
Contributor

Goorzhel commented Jun 26, 2024

For what it's worth, grep accepts multiple files but not multiple patterns. When I want both, I do grep -E 'foo|bar|baz' /file1 /file2.

@zacchiro
Copy link
Owner

zacchiro commented Jun 26, 2024 via email

zacchiro added a commit that referenced this issue Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ux User experience, interface, and usability
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants