zsh-users
 help / color / mirror / code / Atom feed
* how to complete argument only if an option was specified?
@ 2008-01-05 15:45 Vadim Zeitlin
  0 siblings, 0 replies; only message in thread
From: Vadim Zeitlin @ 2008-01-05 15:45 UTC (permalink / raw)
  To: zsh-users

 Hello,

 I'm trying to write a completer for htpasswd command (both because it's
useful on its own and as an exercise before writing more complicated
completer for a custom command) but I'm unable to find a way to complete an
argument only if a specified option was given with _arguments. Here is my
current attempt:

#compdef htpasswd

local users
users() {
    compadd $expl[@] $(cut -d: -f1 $line[1])
}

local enc # encryption options (all mutually exclusive)
enc='-m -d -p -s'

_arguments -s \
    '(-D)-c[Create a new file]' \
    '-n[Don''t update file; display results on stdout]' \
    "($enc)-m[Force MD5 encryption of the password]" \
    "($enc)-d[Force CRYPT encryption of the password (default)]" \
    "($enc)-p[Do not encrypt the password (plaintext)]" \
    "($enc)-s[Force SHA encryption of the password]" \
    '(-c)-D[Delete the specified user]' \
    ':password file:_files' \
    ':name of the user:users' \
  - withoutpassword \
  - withpassword \
    '-b[Use the password from the command line rather than prompting for it]' \
    ':password for this user:' && return 0

Unfortunately (but not unexpectedly) it doesn't work and the password is
always completed. This is not a huge problem, of course, as I don't
complete it anyhow but it's annoying and I'd like to know how to deal with
this for my more complicated custom command completer anyhow. So is there
any way to complete password argument only if "-b" option had been given? I
suspect that it can't be done with just _arguments but I don't know what
would be the best/easiest way to do it otherwise.

 Thanks in advance for any hints (or complete solutions :-),
VZ


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-01-05 15:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-05 15:45 how to complete argument only if an option was specified? Vadim Zeitlin

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