zsh-users
 help / color / mirror / code / Atom feed
* The zsh equivalent to Bash's "complete -W" to complete a command using only a list of words
@ 2016-04-09 10:27 Shlomi Fish
  2016-04-09 11:45 ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Shlomi Fish @ 2016-04-09 10:27 UTC (permalink / raw)
  To: zsh-users

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

Hi all,

I am looking for the zsh equivalent of this bash command to complete a
command using a list of words:

            complete -W "$(cat ${__themes_dir}/list-of-themes.txt)" "Theme"

In bash, I can do Theme[space][tab] and it will give me completions only
from the designated words / options / strings.

How can I achieve that using zsh? I want a shell command/built-in for this
- not #compdef / etc.

My Googling/DuckDuckGoing failed me on this.

Regards,

-- Shlomi Fish

-- 
------------------------------------------
Shlomi Fish http://www.shlomifish.org/

Chuck Norris helps the gods that help themselves.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

* Re: The zsh equivalent to Bash's "complete -W" to complete a command using only a list of words
  2016-04-09 10:27 The zsh equivalent to Bash's "complete -W" to complete a command using only a list of words Shlomi Fish
@ 2016-04-09 11:45 ` Peter Stephenson
  2016-04-09 13:40   ` Shlomi Fish
       [not found]   ` <CANy4znWAhsamgKrpOqmWCNqOWuzwzvXRLSWL6=X8bo6CeH-eZg__45121.4810986587$1460209332$gmane$org@mail.gmail.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 2016-04-09 11:45 UTC (permalink / raw)
  To: zsh-users

On Sat, 09 Apr 2016 13:27:39 +0300
Shlomi Fish <shlomif@gmail.com> wrote:
> I am looking for the zsh equivalent of this bash command to complete a
> command using a list of words:
> 
>             complete -W "$(cat ${__themes_dir}/list-of-themes.txt)" "Theme"
> 
> In bash, I can do Theme[space][tab] and it will give me completions only
> from the designated words / options / strings.

Assuming you have the completion system already loaded, the following is
a fairly standard way of doing it.  The "_wanted" business makes it fit
in with the standard conventions.

pws


_Theme() {
  local expl
  local -a themes
  themes=($(<${__themes_dir}/list-of-themes.txt))
  _wanted tests expl -a themes
}
compdef _Theme Theme


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

* Re: The zsh equivalent to Bash's "complete -W" to complete a command using only a list of words
  2016-04-09 11:45 ` Peter Stephenson
@ 2016-04-09 13:40   ` Shlomi Fish
  2016-04-09 13:49     ` Peter Stephenson
       [not found]   ` <CANy4znWAhsamgKrpOqmWCNqOWuzwzvXRLSWL6=X8bo6CeH-eZg__45121.4810986587$1460209332$gmane$org@mail.gmail.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Shlomi Fish @ 2016-04-09 13:40 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

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

Hi Mr. Stephenson!

thanks for your reply.

On Sat, Apr 9, 2016 at 2:45 PM, Peter Stephenson <p.stephenson@samsung.com>
wrote:

> On Sat, 09 Apr 2016 13:27:39 +0300
> Shlomi Fish <shlomif@gmail.com> wrote:
> > I am looking for the zsh equivalent of this bash command to complete a
> > command using a list of words:
> >
> >             complete -W "$(cat ${__themes_dir}/list-of-themes.txt)"
> "Theme"
> >
> > In bash, I can do Theme[space][tab] and it will give me completions only
> > from the designated words / options / strings.
>
> Assuming you have the completion system already loaded, the following is
> a fairly standard way of doing it.  The "_wanted" business makes it fit
> in with the standard conventions.
>
> pws
>
>
> _Theme() {
>   local expl
>   local -a themes
>   themes=($(<${__themes_dir}/list-of-themes.txt))
>   _wanted tests expl -a themes
> }
> compdef _Theme Theme
>

In addition to that I was told on IRC that I can do this:

    compdef "_values $description $val1 $val2 $val3 $val4..." Theme

Where $description is a short description and $val1 $val2 are the values.

Thanks again.

Regards,

-- Shlomi

-- 
------------------------------------------
Shlomi Fish http://www.shlomifish.org/

Chuck Norris helps the gods that help themselves.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

* Re: The zsh equivalent to Bash's "complete -W" to complete a command using only a list of words
  2016-04-09 13:40   ` Shlomi Fish
@ 2016-04-09 13:49     ` Peter Stephenson
  2016-04-09 14:49       ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2016-04-09 13:49 UTC (permalink / raw)
  To: zsh-users

On Sat, 09 Apr 2016 16:40:52 +0300
Shlomi Fish <shlomif@gmail.com> wrote:
> In addition to that I was told on IRC that I can do this:
> 
>     compdef "_values $description $val1 $val2 $val3 $val4..." Theme
> 
> Where $description is a short description and $val1 $val2 are the values.

Yes, it does work... you learn something new every day.

pws


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

* Re: The zsh equivalent to Bash's "complete -W" to complete a command using only a list of words
  2016-04-09 13:49     ` Peter Stephenson
@ 2016-04-09 14:49       ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2016-04-09 14:49 UTC (permalink / raw)
  To: zsh-users

On Apr 9,  2:49pm, Peter Stephenson wrote:
}
} On Sat, 09 Apr 2016 16:40:52 +0300
} Shlomi Fish <shlomif@gmail.com> wrote:
} > In addition to that I was told on IRC that I can do this:
} > 
} >     compdef "_values $description $val1 $val2 $val3 $val4..." Theme
} > 
} > Where $description is a short description and $val1 $val2 are the values.
} 
} Yes, it does work... you learn something new every day.

And of course to literally satisfy the "I want a shell command/built-in
for this" request, there's always the venerable

    compctl -X $description -k "($val1 $val2 $val3 $val4...)" Theme



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

* Re: The zsh equivalent to Bash's "complete -W" to complete a command using only a list of words
       [not found]   ` <CANy4znWAhsamgKrpOqmWCNqOWuzwzvXRLSWL6=X8bo6CeH-eZg__45121.4810986587$1460209332$gmane$org@mail.gmail.com>
@ 2016-04-09 17:45     ` Daniel Shahaf
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Shahaf @ 2016-04-09 17:45 UTC (permalink / raw)
  To: Shlomi Fish; +Cc: Peter Stephenson, zsh-users

Shlomi Fish wrote on Sat, Apr 09, 2016 at 16:40:52 +0300:
>     compdef "_values $description $val1 $val2 $val3 $val4..." Theme
> 
> Where $description is a short description and $val1 $val2 are the values.

That's vulnerable to shell injection.

You need either to change "" to '' or to change «$foo» to «${(q)foo}»,
depending on whether you intend the variables to be interpolated at the
time you run compdef or at the time you invoke the completion.

Cheers,

Daniel
(I realize you might have intended those variables as metasyntax...)


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

end of thread, other threads:[~2016-04-09 17:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-09 10:27 The zsh equivalent to Bash's "complete -W" to complete a command using only a list of words Shlomi Fish
2016-04-09 11:45 ` Peter Stephenson
2016-04-09 13:40   ` Shlomi Fish
2016-04-09 13:49     ` Peter Stephenson
2016-04-09 14:49       ` Bart Schaefer
     [not found]   ` <CANy4znWAhsamgKrpOqmWCNqOWuzwzvXRLSWL6=X8bo6CeH-eZg__45121.4810986587$1460209332$gmane$org@mail.gmail.com>
2016-04-09 17:45     ` 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).