Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Context-sensitive completion args?



On Thursday 15 September 2005 05:59, Lusk, Andrew wrote:
> I'd like to be able to complete one argument, with access to the completed
> value of another argument.  Like so:
>
> foocmd --arg1=a --arg2=
>
> and in the completion code for arg2, have access to the value of arg1 (a). 
> Is this possible?
>

Yes, use _arguments function. It will parse the whole line and store existing 
arguments/values in hash opt_args. Something like

_arguments \
	"--arg1:arg1 description:(a b c)"\
	"--arg2:arg2 decsription:_foocmd_arg2"

function _foocmd_arg2 () {
	if [[ ${+opt_args[--foo2]} ]]; then
		local arg1=$opt_args[--arg1]
		... do something with arg1
	fi
}

if empty value is the same no value at all you may just skip check for key 
existence.

HTH

-andrey

Attachment: pgpu9wCUcT8lf.pgp
Description: PGP signature



Messages sorted by: Reverse Date, Date, Thread, Author