* [PATCH] Fix pgrep/pkill -f completion
@ 2021-05-21 12:59 Marlon Richert
2021-05-25 7:42 ` dana
0 siblings, 1 reply; 5+ messages in thread
From: Marlon Richert @ 2021-05-21 12:59 UTC (permalink / raw)
To: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 70 bytes --]
Old completion produced false positives & took too much screen space.
[-- Attachment #2: 0001-Fix-pgrep-pkill-f-completion.txt --]
[-- Type: text/plain, Size: 1334 bytes --]
From 112968b31ea926a40a640921f53b71a7f57c0f52 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Fri, 21 May 2021 15:56:42 +0300
Subject: [PATCH] Fix pgrep/pkill -f completion
Old completion produced false positives & took too much screen space.
---
Completion/Unix/Command/_pgrep | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index 51a4883df..22871dd20 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -166,9 +166,16 @@ case $state in
ispat=""
fi
if (( ${+opt_args[-f]} )); then
- _wanted process-args expl $ispat'process command line' \
- compadd ${${(f)"$(_call_program process-args ps -A -o args=)"}% *}
- else
+ local -a matches=( ${(f)"$(
+ _call_program process-args pgrep -lf ${${:-$PREFIX$SUFFIX}:-.\*}
+ )"} )
+ local -a displ=( "${${matches[@]//':'/'\:'}[@]/ /:}" )
+ matches=( "${matches[@]##<-> }" )
+
+ local desc=$ispat'process command line'
+ _description process-args expl "$desc"
+ _describe -t process-args "$desc" displ matches "$@" -U "$expl[@]"
+ else
_wanted processes-names expl $ispat'process name' _process_names -a -t
fi
;;
--
2.31.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix pgrep/pkill -f completion
2021-05-21 12:59 [PATCH] Fix pgrep/pkill -f completion Marlon Richert
@ 2021-05-25 7:42 ` dana
2021-06-07 22:32 ` Lawrence Velázquez
0 siblings, 1 reply; 5+ messages in thread
From: dana @ 2021-05-25 7:42 UTC (permalink / raw)
To: Marlon Richert; +Cc: Zsh hackers list
On 21 May 2021, at 07:59, Marlon Richert <marlon.richert@gmail.com> wrote:
> Old completion produced false positives & took too much screen space.
There are a few issues with this:
1. procps-ng needs -a or -la instead of -lf to get the expected output. I
can't recall off the top of my head whether *BSD and Solaris -lf output
will work, but for now i'll assume so
2. The pgrep command needs -- in case the pattern starts with -
3. The pattern needs quoted again, since it's being passed to eval
4. There's an error in the :-escaping
5. On my macOS machine there's now a delay of about 5 seconds before the full
possibilities are shown, whereas the previous method was pretty much
instantaneous. I guess this is something to do with the large size of the
full output on my Mac (65'000+ chars due to the paths i mention below),
since it's much faster if i include a $PREFIX. But the parameter expansions
shouldn't be that slow with just 64K of text, so maybe it's an inefficiency
in _describe? I didn't look into it much
6. It's not a problem with the change *per se*, but the default
max-matches-width can make the menu really irritating when you have several
PIDs corresponding to the same command; they push the actual command line
off the edge of the screen, and since on macOS you have a million things in
the list that begin with long absolute paths, you just get a whole screen
full of...
1008 /System/Library/PrivateFrameworks/Pa
1077 /System/Library/PrivateFrameworks/Us
1099 /System/Library/PrivateFrameworks/IM
1204 /System/Library/PrivateFrameworks/Ke
... which is not very helpful at a glance.
idk if anything should even be done about that, but i thought i'd mention
it at least
Attached fixes the first four issues
(Not sure i understand the weird indentation rules for continuation in
completion functions — i never followed them before but i remember someone
mentioned them recently — lmk if i messed it up)
PS: This change didn't introduce it, but the $ispat thing doesn't make sense
to me. It implies that -x is a literal match, which isn't the case; it's a
pattern match either way. I've included a second patch that hopefully makes
that distinction more accurate/meaningful. (Use -C2 if applying out of order)
dana
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index e10f42f53..bde681dd2 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -170,10 +170,13 @@ case $state in
ispat=""
fi
if (( ${+opt_args[-f]} )); then
+ local -a opts=( -lf )
+ [[ $OSTYPE == linux* ]] && opts=( -a )
local -a matches=( ${(f)"$(
- _call_program process-args pgrep -lf ${${:-$PREFIX$SUFFIX}:-.\*}
+ _call_program process-args pgrep ${(@q)opts} -- \
+ ${(q)${${:-$PREFIX$SUFFIX}:-.\*}}
)"} )
- local -a displ=( "${${matches[@]//':'/'\:'}[@]/ /:}" )
+ local -a displ=( "${${matches[@]//:/\:}[@]/ /:}" )
matches=( "${matches[@]##<-> }" )
local desc=$ispat'process command line'
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index bde681dd2..38b1aebd8 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -167,7 +167,7 @@ case $state in
(pname)
local ispat="pattern matching "
if (( ${+opt_args[-x]} )); then
- ispat=""
+ ispat+="full "
fi
if (( ${+opt_args[-f]} )); then
local -a opts=( -lf )
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix pgrep/pkill -f completion
2021-05-25 7:42 ` dana
@ 2021-06-07 22:32 ` Lawrence Velázquez
2021-06-07 22:36 ` Lawrence Velázquez
0 siblings, 1 reply; 5+ messages in thread
From: Lawrence Velázquez @ 2021-06-07 22:32 UTC (permalink / raw)
To: zsh-workers; +Cc: dana, Marlon Richert
On Tue, May 25, 2021, at 3:42 AM, dana wrote:
> On 21 May 2021, at 07:59, Marlon Richert <marlon.richert@gmail.com> wrote:
> > Old completion produced false positives & took too much screen space.
>
> There are a few issues with this:
>
> [...]
>
> Attached fixes the first four issues
Any additional feedback on Marlon's original patch or on dana's
alternatives?
--
vq
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix pgrep/pkill -f completion
2021-06-07 22:32 ` Lawrence Velázquez
@ 2021-06-07 22:36 ` Lawrence Velázquez
2021-06-09 4:11 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Lawrence Velázquez @ 2021-06-07 22:36 UTC (permalink / raw)
To: zsh-workers; +Cc: dana, Marlon Richert
On Mon, Jun 7, 2021, at 6:32 PM, Lawrence Velázquez wrote:
> Any additional feedback on Marlon's original patch or on dana's
> alternatives?
Er, I mean just on dana's alternatives. I overlooked Oliver's
commit of the original patch.
--
vq
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix pgrep/pkill -f completion
2021-06-07 22:36 ` Lawrence Velázquez
@ 2021-06-09 4:11 ` Bart Schaefer
0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2021-06-09 4:11 UTC (permalink / raw)
To: Lawrence Velázquez; +Cc: Zsh hackers list, dana, Marlon Richert
On Mon, Jun 7, 2021 at 3:37 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> Er, I mean just on dana's alternatives.
I think dana should commit them.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-06-09 4:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 12:59 [PATCH] Fix pgrep/pkill -f completion Marlon Richert
2021-05-25 7:42 ` dana
2021-06-07 22:32 ` Lawrence Velázquez
2021-06-07 22:36 ` Lawrence Velázquez
2021-06-09 4:11 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).