From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29494 invoked from network); 3 Oct 2020 08:15:48 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 3 Oct 2020 08:15:48 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1601712948; b=Yd5qNpL/R3STOXzOCfMQ987Q100yHpAZTosGeuQUxaDlUKQJVweD2NblPD9CDYEw64Elxc832s gYzjV9aq+Rz00wq3RjTDjh7Fwyp8pUHF4oyB2Qlc5/vC9CwfIlMDgDvVlePlnjgrMBEK524wEP zpsUXLGeNjW7pPBcWPXMwpJVzw3B6g5eTHFkp9kc60WalVaqDEkB1b2ij0ehdFEBI43MPQGdiD Q6AglHPHqrllQ6Ok0m59vQdh6geYTsjXPP8Gdg/yPTJsfxkW/p9jbTyuENdPtAukRvFdCBUb4n YJ0W9dqNl66IoDnlihaOqBBwwuHwrkDlBcUG3sZGAFvg0w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-io1-f41.google.com) smtp.remote-ip=209.85.166.41; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1601712948; bh=axNQzLfyaiuWpp6hFJRFh5Jr3QhS+iMbqceNQENrlFU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=KWs4nkAZmgvCclUwhNHYhjEPIjoZOe6Pk5IqdKn/ENyfgoRTBguxlnPs/XzsoQyov0bHJFlFcx lyuZ/jiUSjBseHDUods9p/2VyhYegJfGNpuVGF9V7b/fMZ5BSIMNyimSJ3HksswCkmjkii99bn lR3wXs5o6PVpTqaaFIl0Ze96DaR1nQAOOjOorqw7aUVewyndqc/yzxMyJxQ5/ihm6ZB6mh4G4o wjqhuJgp4RceuIBVWF1XFWaiA77oEjzPci6fAYfDFFQ0DPaO4pgSChoQk2M0+5XYGexoq6Zoyu ARB1lIAnv0MUgsZhVX4jBTIreb4Nzf2u+19POm6e4ox+Pw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=UMSvZ+Yu9cy9uxHdxRoO0J5N7svMF7g0ISORR8UE408=; b=jrx+HQYck/2VzI9ckUFLLJzcV5 fJgq53Gf+7lp/PTqBVELKxVhO/mMH0JvjhwxuixPhdZgt4FFT8d1gr7sEK964M+EeMj+N5j4gemsz Y4aKw8nQdDlfvwtE3nAIZuaUC4zL0rdEtHgCzoQvQjL+EGsIGKQGfDbwfCbYOjr8w/Z/37HuB9XWi 7I23x6+SC6Or7ptGWSVlRD3DdKlTe0yqrZ6Jhr+4qqgmP++ycHe0dk3DYeSGq8P7WWq6JYVq3fO6A XPAmaX7krw32zURaqE96DNI/nUJmiuOV5ETgObw7fY+/H/bXp/0tRHT8MFJydz4D43UAd2NZr+0pZ FcRm/C7A==; Received: from authenticated user by zero.zsh.org with local id 1kOchm-000PtQ-K9; Sat, 03 Oct 2020 08:15:46 +0000 Authentication-Results: zsh.org; iprev=pass (mail-io1-f41.google.com) smtp.remote-ip=209.85.166.41; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-io1-f41.google.com ([209.85.166.41]:38981) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kOchT-000PkL-12; Sat, 03 Oct 2020 08:15:29 +0000 Received: by mail-io1-f41.google.com with SMTP id v8so4009116iom.6; Sat, 03 Oct 2020 01:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UMSvZ+Yu9cy9uxHdxRoO0J5N7svMF7g0ISORR8UE408=; b=tcn92aOXIjcYStouDQj3lkRhU0sHzwZGy1HxyJclx2gi8T5ayxmuaCb8pmb11umR7e 5uvE58zQZeSMzqR4Lzk1orvMNRg3bsU24k6c7429djVPVRv/kYhOkhoPBrvEuhM7knB8 nFwaKUCsFa649LJ3IcM0sY/kXTamBa1ApHXKQhezHU0eDvrP+Z/VXhhyAJ3mtOX1p3Wu izPo3v40v/lrKWfCG97tkcaQCDXOhpp2F2USWvGzil7htnCMuybhUi4H3/AKYsffVrnw iLFCrBU7wZ7S63u9EAtaX0L8um0S/Fgk1xUu+Vy68l7VwMs1O4SLvIoOmRo7Rd5J57g+ 3b1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UMSvZ+Yu9cy9uxHdxRoO0J5N7svMF7g0ISORR8UE408=; b=PiW14OK/N/N2Bvwf/tzG4rqBaoZDQDtI2cy2uWocoWEMZ+LMIohgYbKRGHYNdBzbNq 18dEI1Jj/smeFA6UvPNESY8ebGG34TCWShz2SOAPrrlLY6rEaKHFmCqN0rSJeTVeekCk 7GIO9A4m5kEsQGjuSIsbTl45EUuHEgBFjtYXEtvLjOdruuiKXhZFPy/YLBC+mlemAD12 ceUFC3u48IZmLYbeHu+mK7WDSxFQxUwEe/rqaROEJLgl1uQ6fqOGB7dWUeTiYMxH2cZx qx8xszrvWq1sq5zU7Ga86GShUhbx/E2S2OGKUSzIf/PMZKDHRfvDQ1zxR9CWCHgoSszI YZmw== X-Gm-Message-State: AOAM533a+ZXZ4oxUOqNdJue+zlcuSTsvaymXVSMpMpWoA2Mnk1GLKHLi diIZaWRBEhgfnkRx7qzBrQM4vCZVayTCQ8tnFViD1MURE1m/Iw== X-Google-Smtp-Source: ABdhPJw//DOj8iykyN1on3G/Y5MFjKylX3Kx8J9fDuG2dcwsN7GahJRPqIDJSX/JWshMhVSnT5hJgHYSnJoKa7ZWhG0= X-Received: by 2002:a5d:96ce:: with SMTP id r14mr4714013iol.146.1601712924951; Sat, 03 Oct 2020 01:15:24 -0700 (PDT) MIME-Version: 1.0 References: <72371-1601655966.237415@B17K.ueth.p0Xz> In-Reply-To: <72371-1601655966.237415@B17K.ueth.p0Xz> From: Justin Garrison Date: Sat, 3 Oct 2020 01:15:13 -0700 Message-ID: Subject: Re: compadd not returning completion options To: Oliver Kiddle Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary="000000000000ec896f05b0bfd9af" X-Seq: 47422 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: --000000000000ec896f05b0bfd9af Content-Type: text/plain; charset="UTF-8" Thank you so much for taking the time to reply. I wish I had known about __complete_debug widget before. When I used it I quickly noticed that after my completion runs (and adds the completions I want) _bash_complete runs which calls +_default:5> zstyle -s :completion::complete:k:: use-compctl ctl which then proceeds to try and match files starting with my special characters (easily confirmed by creating some dummy files starting with those characters) +_path_files:467> tmp1=( completions foo _foo go.mod go.sum LICENSE main.go main_test.go Makefile README.md ) ... +_path_files:516> compadd -D tmp1 -M 'r:|[._-]=* r:|=* l:|=*' -a tmp1 There's a whole lot more it does that I'm not sure where it comes from and finally I see +_main_complete:357> zformat -f mesg ' %F{red}-- no matches found --%f' 'd:`file''' D:file +_main_complete:358> compadd -x ' %F{red}-- no matches found --%f' So I think if I can figure out how to make + @ and : not complete filenames I might be set. Looking through all the commands and flags that are generated by kubectl completion I'm sure it's possible but I'll need to figure it out. Thank you for the help and pointing in me in the right direction. -- Justin Garrison justingarrison.com On Fri, Oct 2, 2020 at 9:26 AM Oliver Kiddle wrote: > Justin Garrison wrote: > > I have a custom completion script I'm working on that has a few different > > functions used for completion (I'm modifying existing completion scripts > so I > > can't change some of them) > > > > __start_k -> calls __k_handle_word -> calls __k_handle_kspace -> calls > > __k_kspace_parse_config > > Lots of nested functions is fairly common and is unlikely to be the > source of problems unless you forget to declare variables local. You > seem to have a number of variables that perhaps ought to be local such > as cur. > > > I can see it being run if I set -x in that function (I'm echoing the > array at > > the end of the compadd command and also tried with -a array_name) > > Rather than use set -x, I'd recommend using the _complete_debug widget. > By default, pressing Ctrl-X followed by ? where you'd normally press > tab will invoke that. Then use up-history to retrieve the file with > the dumped trace information and if you use less as your pager, the & > command to filter it is very useful. > > > +__k_kspace_parse_config:33> compadd -X CONTEXTS -P + -S '' bottlerocket > > In itself, that compadd command looks fine. The -P option here adds a + > prefix at the beginning of the current word while your tests of > $words[CURRENT-1] look at the previous. > > The functions are quite hard to follow with all the bash stuff in there. > The setopts in __k_bash_source() would break things if you've contrived > for them to apply within the zsh completion but I doubt that's the case. > > Just to rule other problems sources out, I'd suggest renaming your > commands array so that it doesn't clash with the builtin variable from > zsh/parameters. > > > $: k + > > -- no matches found -- > > > > but this returns no matches even though the k_out array has values. > > Where is the cursor, directly after the + or in the following (empty) > word? > > Unlike bash. zsh "matches" the completion candidates against what is > already on the command-line so "no matches found" can mean that > candidates were added but none matched. Matching is done against $PREFIX > and $SUFFIX with any extra characters allowed in between (where the > cursor is). The assignment to PREFIX in __k_handle_reply() if it is > called may cause issues. It is common to move characters from the start > of $PREFIX to the end of $IPREFIX, usually by calling compset -P to do > that job. For debug, it can be helpful to dump the contents of those > variables to a separate tty before calls to compadd. > > I'd suggest you simplify your test cases somewhat by replacing some > complex functions with very simple ones that just do something like > compadd one two three. Or perhaps copy the exact compadd that you see in > the trace output. > > Without kubectl (and k) installed, I don't even get as far as the > failure you describe when trying out your function. It is irrelevant to > this but k doesn't seem like a great idea for naming. Single letters are > common choices for people's own aliases. > > Oliver > --000000000000ec896f05b0bfd9af Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you so much for taking the time to reply. I wish I had kno= wn about __complete_debug widget before. When I used it I quickly noticed t= hat after my completion runs (and adds the completions I want) _bash_comple= te runs which calls=C2=A0

+_default:5> zstyle -s :completion::complet= e:k:: use-compctl ctl

which then proceeds=C2=A0to try and match file= s starting with my special characters (easily confirmed by creating some du= mmy files starting with those characters)=C2=A0

+_path_files:467> tmp= 1=3D( completions foo _foo go.mod go.sum LICENSE main.go main_test.go Makef= ile README.md )
...
+_path_files:516> compadd -D tmp1 -M 'r:|[._-]= =3D* r:|=3D* l:|=3D*' -a tmp1=C2=A0

There's a whole lot more= it does that I'm not sure where it comes from and finally I see
<= div class=3D"gmail_default" style=3D"font-family:tahoma,sans-serif">
+_m= ain_complete:357> zformat -f mesg ' %F{red}-- no matches found --%f&= #39; 'd:`file''' D:file =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
+_main_complete:358> compadd -x &= #39; %F{red}-- no matches found --%f'

So I think if I can figure= out how to make=C2=A0+=C2=A0@ and : not complete filenames I might be set.=
= Looking through all the commands and flags that are generated by kubectl co= mpletion I'm sure it's possible but I'll need to figure it out.=
=
Thank you for the help and pointing in me in the right direction.
=

--
Justin Garrison
justingarrison.com
<= /div>


On Fri, Oct 2, 2020 at 9:26 AM Oliver Kiddle <opk@zsh.org> wrote:
Justin Garrison wrote:
> I have a custom completion script I'm working on that has a few di= fferent
> functions used for completion (I'm modifying existing completion s= cripts so I
> can't change some of them)
>
> __start_k -> calls __k_handle_word -> calls __k_handle_kspace -&= gt; calls
> __k_kspace_parse_config

Lots of nested functions is fairly common and is unlikely to be the
source of problems unless you forget to declare variables local. You
seem to have a number of variables that perhaps ought to be local such
as cur.

> I can see it being run if I set -x in that function (I'm echoing t= he array at
> the end of the compadd command and also tried with -a array_name)

Rather than use set -x, I'd recommend using the _complete_debug widget.=
By default, pressing Ctrl-X followed by ? where you'd normally press tab will invoke that. Then use up-history to retrieve the file with
the dumped trace information and if you use less as your pager, the & command to filter it is very useful.

> +__k_kspace_parse_config:33> compadd -X CONTEXTS -P + -S ''= bottlerocket

In itself, that compadd command looks fine. The -P option here adds a +
prefix at the beginning of the current word while your tests of
$words[CURRENT-1] look at the previous.

The functions are quite hard to follow with all the bash stuff in there. The setopts in __k_bash_source() would break things if you've contrived=
for them to apply within the zsh completion but I doubt that's the case= .

Just to rule other problems sources out, I'd suggest renaming your
commands array so that it doesn't clash with the builtin variable from<= br> zsh/parameters.

> $: k +
> =C2=A0-- no matches found --
>
> but this returns no matches even though the k_out array has values.
Where is the cursor, directly after the + or in the following (empty)
word?

Unlike bash. zsh "matches" the completion candidates against what= is
already on the command-line so "no matches found" can mean that candidates were added but none matched. Matching is done against $PREFIX and $SUFFIX with any extra characters allowed in between (where the
cursor is). The assignment to PREFIX in __k_handle_reply() if it is
called may cause issues. It is common to move characters from the start
of $PREFIX to the end of $IPREFIX, usually by calling compset -P to do
that job. For debug, it can be helpful to dump the contents of those
variables to a separate tty before calls to compadd.

I'd suggest you simplify your test cases somewhat by replacing some
complex functions with very simple ones that just do something like
compadd one two three. Or perhaps copy the exact compadd that you see in the trace output.

Without kubectl (and k) installed, I don't even get as far as the
failure you describe when trying out your function. It is irrelevant to
this but k doesn't seem like a great idea for naming. Single letters ar= e
common choices for people's own aliases.

Oliver
--000000000000ec896f05b0bfd9af--