zsh-users
 help / color / mirror / code / Atom feed
* Completing on options in name=value format?
@ 2003-02-03 22:48 Bill Burton
  2003-02-11  8:11 ` Oliver Kiddle
  0 siblings, 1 reply; 2+ messages in thread
From: Bill Burton @ 2003-02-03 22:48 UTC (permalink / raw)
  To: Zsh Users List

Hello,

I'm writing a completion function for some home grown scripts that 
require options in the format name=value.  I'm having two problems with 
my function:

The command is as follows with the area and pf options required but the 
test option is not:
   startws area=<a subdirecties under /usr/local> \
           pf=<a file with a .pf suffix relative to
              the directory completed in the area option>
           test={yes|no}

In order to complete the pf option, the area option must be specified first.

The function mostly works but I still have the following issues:

1. After I complete on the area= option, it still shows up on the 
completion menu.

2. The .pf suffix for the filename on the pf option isn't stripped off.

3. After completing an option and its argument, there's an extranious 
"=" appended to the end:
        startws area=intra=
    Upon entering a space, it's removed but it shouldn't be
    there to begin with.

This is the function so far:

#compdef startws servedb shutdb

local curcontext="$curcontext" state line expl area_dirs
typeset -A val_args

case "$service" in
startws|servedb|shutdb)
_values -C -s = "Options" \
   'area[area directory]:area:->areas' \
   'pf[parameter file]:parameter file:->pf' \
   'test[test or trace mode]::test:(yes no)' \
   && return 0
   ;;

esac

[[ -n "$state" ]] &&
case "$state" in
areas)
   # directories contain a conf/ subdir one or two levels down
   area_dirs=( ${BASEDIR:-/usr/local}/*/conf
               ${BASEDIR:-/usr/local}/*/*/conf )
   # TODO: filter out certain directories
   # lop off the prefix, i.e. /usr/local/ and /conf suffix
   area_dirs=( ${${area_dirs#${BASEDIR:-/usr/local/}}%/conf} )
   compadd -qS = -a area_dirs
   ;;

pf)
   local area
   for w in $words; do
     case "$w" in
       area=*)
         area=${w#area=}
         break;
         ;;
     esac
   done
   # BUG: -s .pf doesn't strip off the .pf suffix
   [[ -n $area ]] && compadd -f -W ${BASEDIR:-/usr/local}/${area}/conf/ 
-g \*.pf -s .pf

   ;;

esac

return 1


Thanks for any assistance,
-Bill


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

* Re: Completing on options in name=value format?
  2003-02-03 22:48 Completing on options in name=value format? Bill Burton
@ 2003-02-11  8:11 ` Oliver Kiddle
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2003-02-11  8:11 UTC (permalink / raw)
  To: Bill Burton; +Cc: Zsh Users List

On 3 Feb, Bill Burton wrote:
> I'm writing a completion function for some home grown scripts that 
> require options in the format name=value.  I'm having two problems with 
> my function:
> 
> The command is as follows with the area and pf options required but the 
> test option is not:
>    startws area=<a subdirecties under /usr/local> \
>            pf=<a file with a .pf suffix relative to
>               the directory completed in the area option>
>            test={yes|no}
> 
> In order to complete the pf option, the area option must be specified first.
> 
> The function mostly works but I still have the following issues:
> 
> 1. After I complete on the area= option, it still shows up on the 
> completion menu.

In zsh 4.1 there is a -w option to _values that will fix this. _values
isn't as good as I'd like. The issues were discussed in depth in
relation to _dd if you want to search the archives for it.
 
> 2. The .pf suffix for the filename on the pf option isn't stripped off.

I think you've misunderstood what -s to compadd does. -W and -g are
options to _files and not compadd.

How you should write it depends on whether you want to complete
subdirectories along with .pf files. If not,
  compadd ${BASEDIR:-/usr/local}/${area}/conf/*.pf(:r:t)
should do it.

> 3. After completing an option and its argument, there's an extranious 
> "=" appended to the end:

That's what you told it to do in the line:
   compadd -qS = -a area_dirs

At least in 4.1, your -s = argument to _values is redundant. -S specifies
the separator between values and their arguments (default =) while -s
specifies the value separator.

Oliver

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


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

end of thread, other threads:[~2003-02-11  8:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-03 22:48 Completing on options in name=value format? Bill Burton
2003-02-11  8:11 ` Oliver Kiddle

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