zsh-users
 help / color / mirror / code / Atom feed
From: "Daniel Shahaf" <d.s@daniel.shahaf.name>
To: zsh-users@zsh.org
Subject: Re: What is the _services array?
Date: Fri, 27 May 2022 15:29:55 +0000	[thread overview]
Message-ID: <f981c88a-cad7-44ca-ad9d-270576b5ccc2@www.fastmail.com> (raw)
In-Reply-To: <361201244.437080.1653656473288@mail2.virginmedia.com>

Peter Stephenson wrote on Fri, 27 May 2022 13:01 +00:00:
>> On 27 May 2022 at 13:45 Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>> Peter Stephenson wrote on Fri, 27 May 2022 09:52 +00:00:
>> >> On 27 May 2022 at 10:09 Zach Riggle <zachriggle@gmail.com> wrote:
>> >> I recently found the _services array by playing around with "typeset -H"
>> >> and there's some neat stuff in here, I'm just not sure what it's for or how
>> >> to make use of it.
>> >> 
>> >> Any ideas?
>> >
>> > This is the backend DB for the feature described in the zshcompsys manual
>> > in the paragraph that starts
>> >
>> > "Each  name may also be of the form `cmd=service'.  "
>> >
>> > You should be able to be configure it by the means noted there.
>> 
>> It's not documented, though, which means it's liable to change
>> incompatibly without notice.  If that's not the case, then we should
>> document that function :)
>
> My inclination would be that if Zach finds things he can do with _services
> that aren't part of the existing interface,

I can't comment about $_services, but here's two things I've used
$_comps for:

1. Providing a fallback completion function:

       _has_completion() { (( $# == 1 )) || return 2; (( ${+_comps[$1]} )) }
       _has_completion ag || compdef _gnu_generic ag
       
   This lets ag(1) be completed by «_gnu_generic» if nothing better has been
   registered.

   The helper's completion function is also relevant:

       compdef 'compadd -k _comps' _has_completion

2. Listing commands that don't have completions:

       () { print -rl -- ${(k)commands:|argv} } ${(k)_comps}

   I haven't used this before.

3. Invoking a specific command's completion.

   I use a git() wrapper function to implement a «git cd» command.  To
   complete that, I defined a «_git-cd» function.  That function does
   «__git_worktrees "$@" || ${_comps[cd]} "$@"».

I don't know how to implement the first two via the API.  The third can be done
without ${_comps} using «(( --CURRENT )); shift words; _normal» (on the RHS of the «||»).

> we should probably extend the interface rather than expose the
> implementation detail.  But, of course, it's horse for courses.

On the one hand, +1 to abstraction.  On the one hand, since special parameters
are a thing, exposing an assoc parameter doesn't _necessarily_ mean we
have to use an assoc under the hood forever.

Cheers,

Daniel


      reply	other threads:[~2022-05-27 15:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-27  9:09 Zach Riggle
2022-05-27  9:52 ` Peter Stephenson
2022-05-27 12:45   ` Daniel Shahaf
2022-05-27 13:01     ` Peter Stephenson
2022-05-27 15:29       ` Daniel Shahaf [this message]

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=f981c88a-cad7-44ca-ad9d-270576b5ccc2@www.fastmail.com \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-users@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).