Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Completing on options in name=value format?
- X-seq: zsh-users 5865
- From: Bill Burton <billb@xxxxxxxxxxxx>
- To: Zsh Users List <zsh-users@xxxxxxxxxx>
- Subject: Completing on options in name=value format?
- Date: Mon, 03 Feb 2003 17:48:31 -0500
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Progress Software Corporation
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author