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

Re: Variable expansion problem

"John Cooper" wrote:
> I'd like to have a mechanism such that I can type $FOO<TAB> and have
> it expand to the following which I can then manually edit further:

So you need a literal expansion mechanism for parameters; the usual
mechanism does all forms of expansion and quotes the result.  Of course
there are other possible ways of achieving the effect, such as aliases
and _expand_alias (after the recent fix), but this answers the question

Rather than fiddle with the _expand completer, which is already trying
too hard to be all things to all users, it's probably better to have a
different one (call it _expand_literal_param, or something):


# Expand a parameter literally (no quotation).  Only activates if the entire
# word matches a parameter name.

[[ $val = \$[[:IDENT:]]## ]] || return 1

(( ${(P)+val} )) || return 1

_wanted parameters expl "literal parameter expansion" compadd -UQ "${(P)val}"

Note I've deliberately limited this so it only kicks in if the entire
word matches $<paramname>.  Put that in a function and put
_expand_literal_param in your list of completers immediately before the
existing _expand.  My list became:

zstyle ':completion:*' completer _oldlist _expand_literal_param _expand \
  _complete _ignored _approximate

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


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