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

[REQUEST] Any kind of more advanced process filtering - willing to try to create PR #980

Open
quicknir opened this issue Nov 20, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@quicknir
Copy link

Is your feature request related to a problem? Please describe.

Filtering processes is currently very limited, where you can just type a string literal that seemingly gets matched against the entire "line" of process text (command, arguments, user, etc). One common use case I have is wanting to filter by both user, and process name. There doesn't seem to be any way to do this. Another use case might be wanting to filtering by part of the process name, but also one of the argument names - and so on.

It seems like this issue has been suggested and upvoted considerably in the past, and there was even a PR for it, from a number of years ago.

Describe the solution you'd like
I can see a few possible solutions here, some of which can be combined:

  1. regex
  2. A sort of "fzf" (with --exact) like search. The core idea is very simple: you give multiple terms separated by space, and you filter down to processes that contain all the terms, in any order. So simply searching nir foo will find processes that contain "nir", and "foo", anywhere. This would in practice let me quickly filter processes that have nir as the user and foo as the process name. This idea can be simply extended by treating a leading ! of a group as negation. Spaces are either disallowed from search, or you'd have to escape them or quote them (not sure how useful spaces are anyhow in this context).
  3. fielded search. This combines with either of the other two options, but especially naturally with 2. You allow things of the form u:nir foo, which allows searching for processes that contain nir for the user and foo anywhere. While this is cool, I don't actually personally think this is worth it, as this doesn't solve some issues that 1-2 solve, and 1-2 solves the fielded search problem "well enough" in practice.

Personally, I suggest just implementing 2 with negation, without worrying about escaping spaces. This solves the problem, it's extremely easy to implement, it's more intuitive and easier than regex (worrying about which flavor of regex). It's also agnostic to the "order" of the various text fields of a process. If you go with regex, we still have to consider whether the appropriate search will be nir.*foo or foo.*nir.

If we can agree on the design then I'm willing to try to take a look at the code and make a PR.

@quicknir quicknir added the enhancement New feature or request label Nov 20, 2024
@imwints
Copy link
Contributor

imwints commented Nov 21, 2024

255b777

@quicknir
Copy link
Author

quicknir commented Nov 25, 2024

@imwints Thanks for making me aware of that! Unfortunately, as far as I can see this does not solve the use case I mentioned. Since the regex is matched against every field individually (rather than e.g. against some kind of concatenated string), this doesn't really let me even try to filter processes by both name and user simultaneously. Given that the ! and regex approach is already present, would you be willing to consider something like 3?

nir foo  // same as present; a search for "nir foo" including the space, in any field of the process
!nir.*foo // same as present; regex search in any field of the process
u:nir foo // searches nir in user, foo in any field
u:nir !bar.*foo // searches nir in user, and the regex bar.*foo in any field
u:nir bar foo // searches nir in user, "bar foo" in any field - space is still permitted
u:!(nir|john) bar foo // allows regex search in user too

The only kind of weird case in this is if users do something like foo u:nir bar; it's a little weird how to interpret this so maybe it would be ideal to just error here?

Another option, if you're willing, is for me to implement 2, but make it opt in via user-config - thoughts? This would actually probably be my personal preference.

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

No branches or pull requests

3 participants