zsh-users
 help / color / mirror / code / Atom feed
* completion help
@ 2004-02-14 20:09 Dwight Shih
  2004-02-14 23:31 ` Eric Mangold
  0 siblings, 1 reply; 4+ messages in thread
From: Dwight Shih @ 2004-02-14 20:09 UTC (permalink / raw)
  To: Zsh users list

After years of avoidance, I've finally decided to start playing with
completion. Here's what I've got:

typeset -A opt_args
local contest state line

_arguments -s -S \
  "1:build:(build test start stop deploy validate help)" \
  "*:file:_files" \
  "-conf[specify configuration file]:file:_files" \
  "-a[automate deploy actions]" \
  "-f[force more or copy]" \
  "-m[move jar]" \
  "-c[copy jar]" \
  "-v(vv vvv)[validate output level 1]" \
  "-vv(v vvv)[validate output level 2]" \
  "-vvv(v vv)[validate output level 3]" \
  && return 0

which works as far as it goes.

What I would like to group options by major mode (the first set of
mutually exclusive options: build test start stop deploy validate and
help) so that only valid options for each mode would apply. So -a -f -m
-c would only apply in the deploy mode and -v -vv -vvv would only apply
in the validate mode.

I'd also like to restrict file completions. For example, I would like to
restrict the -conf file completion to be limited to *.xml and the general
file completion to be limited to *.jar.

Thanks for any help that you can provide.

Dwight Shih


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

* Re: completion help
  2004-02-14 20:09 completion help Dwight Shih
@ 2004-02-14 23:31 ` Eric Mangold
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Mangold @ 2004-02-14 23:31 UTC (permalink / raw)
  To: zsh-users

On Sat, 14 Feb 2004 15:09:22 -0500, Dwight Shih <zshlist@ideoplex.com> 
wrote:

> After years of avoidance, I've finally decided to start playing with
> completion. Here's what I've got:
>
> typeset -A opt_args
> local contest state line
>
> _arguments -s -S \
>   "1:build:(build test start stop deploy validate help)" \
>   "*:file:_files" \
>   "-conf[specify configuration file]:file:_files" \
>   "-a[automate deploy actions]" \
>   "-f[force more or copy]" \
>   "-m[move jar]" \
>   "-c[copy jar]" \
>   "-v(vv vvv)[validate output level 1]" \
>   "-vv(v vvv)[validate output level 2]" \
>   "-vvv(v vv)[validate output level 3]" \
>   && return 0
>
> which works as far as it goes.
>
> What I would like to group options by major mode (the first set of
> mutually exclusive options: build test start stop deploy validate and
> help) so that only valid options for each mode would apply. So -a -f -m
> -c would only apply in the deploy mode and -v -vv -vvv would only apply
> in the validate mode.

I could easily be way off on this but I think you want to use "sets". See 
the _arguments documentation.

> I'd also like to restrict file completions. For example, I would like to
> restrict the -conf file completion to be limited to *.xml and the general
> file completion to be limited to *.jar.

The _files documentation explains this. You want to use the -g argument as 
in:
_files -g "*.xml"


	-Eric



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

* Re: completion help
  2007-04-14 14:08 Michael Drzal
@ 2007-04-15 18:57 ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2007-04-15 18:57 UTC (permalink / raw)
  To: zsh-users

On Apr 14, 10:08am, Michael Drzal wrote:
}
} % ssh host<TAB>
} host host.regular host.inband host.outofband
} 
} I realize that I could enumerate all of the possible hosts with the
} hosts style, but this seems like overkill.  Is there some way that I
} could do something like:
} 
} zstyle context domains domain1 domain2 domain3 ...
} 
} and get the effect that I'm looking for?

zstyle -e ':completion:*:(ssh|scp):*' hosts \
    'reply=( ${${words[CURRENT]%.*}#*@}.{domain1,domain2,domain3,...} )'

This will complete the domains directly (with a leading dot) if you
have't already typed the host part.  A conditional test on
$words[CURRENT] could be added to set reply only if there is already
at least one dot.  Additional complexity is of course possible.  You
might also want to put the list of domain names in a variable where
it's more easily edited:

host_domains=( domain1 domain2 domain3 ... )

zstyle -e ':completion:*:(ssh|scp):*' hosts \
    '[[ $words[CURRENT] = *.* ]] && 
     reply=( ${${words[CURRENT]%.*}#*@}.${^host_domains} )'

If you're starting to get really complex conditions, I suggest putting
them into a function and replacing the string value of the style with
a call to the function.


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

* completion help
@ 2007-04-14 14:08 Michael Drzal
  2007-04-15 18:57 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Drzal @ 2007-04-14 14:08 UTC (permalink / raw)
  To: zsh-users

I apologize in advance if this question has been asked before and
answered, but I spent the last couple of days searching the web and
reading docs, and I came up empty handed.

I love the zsh completion system, but I'm having a little trouble
trying to figure out how to setup a specific completion.  I work in an
environment where hosts have DNS entries in multiple domains.  There
is one domain for normal host access, another domain for some form of
inband access (think DRAC on dells or SP/SC on sun hosts), and a third
for out of band access (serial console).  I would like to be able to
complete the domain name for various commands (ssh, ping, traceroute,
...).  I would envision something like:

% ssh host<TAB>
host host.regular host.inband host.outofband

I realize that I could enumerate all of the possible hosts with the
hosts style, but this seems like overkill.  Is there some way that I
could do something like:

zstyle context domains domain1 domain2 domain3 ...

and get the effect that I'm looking for?

  Mike


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

end of thread, other threads:[~2007-04-15 18:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-14 20:09 completion help Dwight Shih
2004-02-14 23:31 ` Eric Mangold
2007-04-14 14:08 Michael Drzal
2007-04-15 18:57 ` Bart Schaefer

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