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

Re: outputs of _users and _hosts to arrays



On Jul 24,  4:05pm, Wataru Kagawa wrote:
} 
} How can I add the outputs of _users and _hosts to arrays?

Those are completion functions.  They don't have output.  They just
call the compadd builtin.

So look up "compadd" in the manual, and you find:

    -O ARRAY
          If this option is given, the WORDS are _not_ added to the set
          of possible completions.  Instead, matching is done as usual
          and all of the WORDS given as arguments that match the string
          on the command line will be stored in the array parameter
          whose name is given as ARRAY.

And therefore:

    _users -O users
    _hosts -O hosts

However, that only works inside functions called by the completion code.
You cannot employ _users and _hosts for generalized programming.

} users=( "$_users[@]" )
} hosts=( "$_hosts[@]" )

That syntax would mean that _users and _hosts were array variables; but
you seem to know that they're functions, so why did you try that?



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