Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: new utility function for mixing in extra values



dana wrote:
> it's not actually a menu, obv. but it looks like one, it's in the same
> place, the descriptions message appears to suggest it's completing
> something. but you can't interact with it

With the menu style you give, there's other things that will also
result in a list without a menu in much the same manner.
  _alternative 'stuff: : _message -e stuff stuff' 'alone:alone:compadd one'

The only way I can find to invoke menu-selection with a single
unambiguous match entails using compadd -E1 and I'm fairly sure that's a
bug where the display only match is included in a count where it
shouldn't be.

> maybe it's not as surprising if you don't use menu selection by default,
> since the list is never interactable in that configuration, but with my
> config at least it is, to me. (actually i find it very confusing either
> way, since there's no indication of why it works differently)

I can see that it might be confusing with your setup but the alternative
is not especially useful - inserting the single match where you probably
wanted to see the description instead. I can't find a simple way to
detect that condition. If you want something changed, it probably needs
something along the lines of the insert-ids style from _pids.

> On Fri 19 Jun 2026, at 23:44, Oliver Kiddle wrote:
> > My preference is to find a way to apply special formatting to the phony
> > matches. So something like the list-colors style. I'm open to ideas on
> > how that might be best be configured.
>
> that'd make it a little clearer maybe. i'm not sure off the top of my
> head though

Following patch is one approach to that. This puts "phony" in the tag
and does a string lookup of list-colors, so usage is, e.g:

   zstyle ':completion:*:phony' list-colors "${.zle.sgr[fake]}"

But this is not how list-colors is otherwise used. Perhaps a different
name for the style? Or maybe pull the real tag out of $_comp_tags?

Oliver

diff --git a/Completion/Base/Utility/_phony b/Completion/Base/Utility/_phony
index 1d53a2ecf..f07c70e39 100644
--- a/Completion/Base/Utility/_phony
+++ b/Completion/Base/Utility/_phony
@@ -10,12 +10,12 @@
 # -E                is only used once (last)
 # -A and -O         results merged as if compadd was used once only
 
-local curcontext="$curcontext" minus
+local curcontext="$curcontext" minus val
 local -i minus strip nm skip ret=1
-local -a phony opts cont amerge omerge phony_amat phony_omat last
+local -a phony opts grp cmat cont amerge omerge phony_amat phony_omat last
 
 zparseopts -D -a opts a=phony k=phony d:=phony l=phony \
-    n F: p: i: P: I: e f s: S: q r: R: M+: J+: V+: 1 2 o+: X+: x+: D: \
+    n F: p: i: P: I: e f s: S: q r: R: M+: J+:=grp V+:=grp 1 2 o+: X+: x+: D: \
     A+:=amerge O+:=omerge \
     E:=last
 
@@ -34,10 +34,16 @@ if (( ! $# )); then # no function passed
 else
   (( minus = argv[(ib:2:)-] ))
   (( minus > $# )) && minus=2 && argv[1]+=( - )
-  argv[minus]=( "$opts[@]" ${=amerge:+-A phony_amat} ${=omerge:+-O phony_omat} "$last[@]" )
+  argv[minus]=( "$opts[@]" "$grp[@]" ${=amerge:+-A phony_amat} ${=omerge:+-O phony_omat} "$last[@]" )
 fi
 
-compadd "$opts[@]" "$amerge[@]" "$omerge[@]" "$phony[@]" && ret=0
+if [[ -z $amerge && -z $omerge && -n $grp ]] &&
+    zstyle -s ":completion:${curcontext}:phony" list-colors val
+then
+  compadd -O cmat "$opts[@]" "$phony[@]"
+  _comp_colors+=( "($grp[2])=(${(j.|.)${(b)cmat}})=$val" )
+fi
+compadd "$opts[@]" "$grp[@]" "$amerge[@]" "$omerge[@]" "$phony[@]" && ret=0
 nm=$compstate[nmatches]
 if (( skip )) || "$@" || [[ -n "$_comp_mesg" ]]; then
   [[ ret -eq 0 && compstate[nmatches] -eq nm && -z "$PREFIX$SUFFIX" ]] &&




Messages sorted by: Reverse Date, Date, Thread, Author