zsh-users
 help / color / Atom feed
* completion for 'alerter'
@ 2020-03-06  4:45 ` TJ Luoma
  2020-03-06  9:51   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: TJ Luoma @ 2020-03-06  4:45 UTC (permalink / raw)
  To: Zsh MailingList

I just learned of a new tool called 'alerter'
(https://github.com/vjeantet/alerter) and wondered if someone could
explain how to make a completion for the various options that it has.
I've never really understood how to create a completion.

For example, when I type 'tar -' followed by 'tab' I get this:

$ tar -[tab]
tar function
A  -- append to an archive
c  -- create a new archive
f  -- specify archive file or device
t  -- list archive contents
u  -- update archive
v  -- verbose output
x  -- extract files from an archive

These are the options for `alerter`

-help
-json
-message VALUE
-remove ID
-list ID
-reply VALUE
-actions VALUE1,VALUE2
-dropdownLabel VALUE
-title VALUE
-subtitle VALUE
-closeLabel VALUE
-sound NAME
-group ID
-sender ID
-appIcon URL
-contentImage URL
-timeout NUMBER

I came across https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org
which is supposed to explain how to write a completion, but I'm afraid
that I don't really follow most of it.

Is there a simpler starter tutorial or does someone have an example
completion that I might be able to modify?

Thanks

Tj

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

* Re: completion for 'alerter'
  2020-03-06  4:45 ` completion for 'alerter' TJ Luoma
@ 2020-03-06  9:51   ` Peter Stephenson
  2020-03-06 15:21     ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2020-03-06  9:51 UTC (permalink / raw)
  To: zsh-users

On Thu, 2020-03-05 at 23:45 -0500, TJ Luoma wrote:
> These are the options for `alerter`
> 
> -help
> -json
> -message VALUE
> -remove ID
> -list ID
> -reply VALUE
> -actions VALUE1,VALUE2
> -dropdownLabel VALUE
> -title VALUE
> -subtitle VALUE
> -closeLabel VALUE
> -sound NAME
> -group ID
> -sender ID
> -appIcon URL
> -contentImage URL
> -timeout NUMBER

Best thing to do for something like this is to copy another
straightforward completion.  For example, a search for something that
handles '-help' reveals Completion/Unix/Command/_tardy in the zsh
distribution --- it doesn't get much simpler than that.  All you really
need to know here is that if there is a colon, the thing immediately
after the colon describes the argument; if there are two colons, the
stuff after the second is completion of the argument (e.g. your VALUE or
ID); the stuff in parentheses is literal value to be completed, and the
things beginning "_" are completion functions to be called to add the
values.  There are functions you can call for pretty much anything
generic e.g. _urls for (surprise!) URLs.  Copy it to _alerter, change
the line at the top to say "#compdef _alerter", change the list of
options, and that's it basically working.

If you want a professionally edited step-by-step guide, your best bet is
probably Oliver's chapter 15 from From Bash to Z Shell,
http://www.bash2zsh.com/ although that web site does have some other
potentially useful links.

pws


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

* Re: completion for 'alerter'
  2020-03-06  9:51   ` Peter Stephenson
@ 2020-03-06 15:21     ` Mikael Magnusson
  0 siblings, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2020-03-06 15:21 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

On 3/6/20, Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Thu, 2020-03-05 at 23:45 -0500, TJ Luoma wrote:
>> These are the options for `alerter`
>>
>> -help
>> -json
>> -message VALUE
>> -remove ID
>> -list ID
>> -reply VALUE
>> -actions VALUE1,VALUE2
>> -dropdownLabel VALUE
>> -title VALUE
>> -subtitle VALUE
>> -closeLabel VALUE
>> -sound NAME
>> -group ID
>> -sender ID
>> -appIcon URL
>> -contentImage URL
>> -timeout NUMBER
>
> Best thing to do for something like this is to copy another
> straightforward completion.  For example, a search for something that
> handles '-help' reveals Completion/Unix/Command/_tardy in the zsh
> distribution --- it doesn't get much simpler than that.  All you really
> need to know here is that if there is a colon, the thing immediately
> after the colon describes the argument; if there are two colons, the
> stuff after the second is completion of the argument (e.g. your VALUE or
> ID); the stuff in parentheses is literal value to be completed, and the
> things beginning "_" are completion functions to be called to add the
> values.  There are functions you can call for pretty much anything
> generic e.g. _urls for (surprise!) URLs.  Copy it to _alerter, change
> the line at the top to say "#compdef _alerter", change the list of
> options, and that's it basically working.

A minor correction that this should say "#compdef alerter" without the
underscore, or it would just complete options to the completer.

-- 
Mikael Magnusson

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20200306044721eucas1p2ef2d8e761171b32b9c49ac98cd8fce8b@eucas1p2.samsung.com>
2020-03-06  4:45 ` completion for 'alerter' TJ Luoma
2020-03-06  9:51   ` Peter Stephenson
2020-03-06 15:21     ` Mikael Magnusson

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git