zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: fix for df completion
Date: Tue, 26 Sep 2023 23:08:54 +0200	[thread overview]
Message-ID: <3500-1695762534.674427@ZhWD.zocD.z1rF> (raw)

When trying to complete options after df, the initial - is just removed.
I narrowed this down to a minimal function to reproduce the problem and
it relates to the use of both -M and -U to compadd in _canonical_paths.
The -M actually comes from _umountable. Matchers have no meaning when
-U is used - all strings are added as matches. The patch below is to
the compadd builtin option handling. If -U was specified, it simply
ignores all matching controls from -M options. This does mean that with
-U, invalid matchers won't produce errors. There must be an underlying
problem down in addmatches() where it should be ignoring dat->match and
the matchers linked list if CAF_MATCH is not set. I'm fine with it if
someone wants to track down this bad logic in the matching code. The
approach below does at least fix df completion and this approach saves
the completion code from having to do quite a big of pointless work.

_umountable also generates some bogus completions on FreeBSD for
automount maps and an empty entry that comes from appending an array to
a variable declared as a scalar. That results in an initial empty array
element.

Oliver

diff --git a/Completion/Unix/Type/_umountable b/Completion/Unix/Type/_umountable
index 6e4988e2d..0111555b6 100644
--- a/Completion/Unix/Type/_umountable
+++ b/Completion/Unix/Type/_umountable
@@ -1,6 +1,6 @@
 #autoload
 local tmp
-local dev_tmp dpath_tmp mp_tmp mline
+local -a dev_tmp dpath_tmp mp_tmp mline
 
 case "$OSTYPE" in
 linux*)
@@ -15,6 +15,7 @@ irix*)
   ;;
 freebsd*|dragonfly*)
   /sbin/mount | while read mline; do
+    [[ $mline[(w)1] = map ]] && continue
     dev_tmp+=( $mline[(w)1] )
     mp_tmp+=( $mline[(w)3] )
   done
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index 96ad7b3f1..342611f1f 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -829,7 +829,9 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 
  ca_args:
 
-    if (mstr && (match = parse_cmatcher(name, mstr)) == pcm_err) {
+    if (mstr && (dat.aflags & CAF_MATCH) &&
+	    (match = parse_cmatcher(name, mstr)) == pcm_err)
+    {
 	zsfree(mstr);
 	zfree(dat.dpar, dparsize);
 	return 1;



                 reply	other threads:[~2023-09-26 21:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3500-1695762534.674427@ZhWD.zocD.z1rF \
    --to=opk@zsh.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).