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

Re: _call_program (and possibly other hooks) or opt_args quoting prob lem.

В Пнд, 20.05.2002, в 20:40, Bart Schaefer написал:
> I don't have this _info completion function, so I'm having a hard time
> coming up with a way to reproduce this.

You do no need to. Just do:

_foo() {
    local context state line ret=1
    typeset -A opt_args

    _arguments \
        '-d[directory]:directory:_files -/' \
        '1:test_arg:->test' && ret=0

    case "$state" in
        test )
            local -a opts
            (( $+opt_args[-d] )) && opts=(-W $opt_args[-d])
            _files $opts && ret=0

    return $ret

mkdir a\ b
touch a\ b/test

and try to complete

foo -d $PWD/a\ b TAB

> Perhaps "${(@qqq)${(@e)argv[2,-1]}}" ?
> Or perhaps drop the `eval' and just use "${(@e)argv[2,-1]}}" directly in
> the latter branch -- the only reason I can think of for the `eval' to be
> there is to expand aliases, and I wouldn't think we'd want to do that when
> inside _call_program, but I could be wrong.
> } Actually I begin to feel that _arguments should eval parameter value
> } before storing it. Can anybody give example when parameter value as it
> } appears on command line is useful? 
> I'm not sure what you mean by "parameter value as it appears" -- is the
> word "value" out of place in that phrase?

Once more:

user enters

$PWD/a\ b

as the "value" of option -d. When this is finally passed to a program
for execution, shell expands $PWD so program actually sees (remove
quotes) "/home/bor/test/a b". This is "real" value of option -d.
Alternatively, we can store it as it appears on the line - i.e. "$PWD/a\
b". _Then_ _call_program would work just fine - by eval'ing this you'd
get exactly the correct value.

What happens currently is, zsh removes quoting when it stores values in
opt_args array but it does not expand it. After this is done there is no
way to recover original string as entered by user. So in cases when you
may want it (see above example _foo) you have no means to get real

Look in trace for above example:

+_foo:11> opts=( -W $PWD/a b )

how do we know that space has been quoted but dollar in $PWD was not?
Any quoting that you apply now will be equally applied to both space and
$ - while you need to leave $ unquoted (for eval).

> What about the _expand completer?

The problem is not to complete the value of option (this works just
fine). The problem is to use this value in completing other parts of

I am sorry if it is confusing but I really do not understand what you do
not understand ... it seems pretty clear to me :-)


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