zsh-users
 help / color / mirror / code / Atom feed
* What is the _services array?
@ 2022-05-27  9:09 Zach Riggle
  2022-05-27  9:52 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Zach Riggle @ 2022-05-27  9:09 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 276 bytes --]

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?

$ for k v in "${(@kv)_services}"; do
 echo "${(q-)k}=${(q-)v}"
done
lzcat=unxz


*Zach Riggle*

[-- Attachment #2: Type: text/html, Size: 674 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is the _services array?
  2022-05-27  9:09 What is the _services array? Zach Riggle
@ 2022-05-27  9:52 ` Peter Stephenson
  2022-05-27 12:45   ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2022-05-27  9:52 UTC (permalink / raw)
  To: Zsh Users

> 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.

pws


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is the _services array?
  2022-05-27  9:52 ` Peter Stephenson
@ 2022-05-27 12:45   ` Daniel Shahaf
  2022-05-27 13:01     ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2022-05-27 12:45 UTC (permalink / raw)
  To: zsh-users

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 :)

That also goes for ${_comps}, which maps command word basenames to their
completion functions (e.g., [[ ${_comps[svn]} == _subversion ]]).

Cheers,

Daniel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is the _services array?
  2022-05-27 12:45   ` Daniel Shahaf
@ 2022-05-27 13:01     ` Peter Stephenson
  2022-05-27 15:29       ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2022-05-27 13:01 UTC (permalink / raw)
  To: zsh-users

> 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, we should probably extend the
interface rather than expose the implementation detail.  But, of course,
it's horse for courses.

pws


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is the _services array?
  2022-05-27 13:01     ` Peter Stephenson
@ 2022-05-27 15:29       ` Daniel Shahaf
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2022-05-27 15:29 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-27 15:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27  9:09 What is the _services array? 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

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).