Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
RE: Variable expansion problem
- X-seq: zsh-users 11878
- From: "John Cooper" <john.cooper@xxxxxxxxxxxxx>
- To: "Peter Stephenson" <pws@xxxxxxx>, <zsh-users@xxxxxxxxxx>
- Subject: RE: Variable expansion problem
- Date: Tue, 25 Sep 2007 12:08:20 +0100
- Cc: "John Cooper" <john.cooper@xxxxxxxxxxxxx>
- In-reply-to: <200709250901.l8P91LYU017875@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <DD74FBB8EE28D441903D56487861CD9D1F554D01@xxxxxxxxxxxxxxxxxxxxxx> <200709250901.l8P91LYU017875@xxxxxxxxxxxxxx>
- Thread-index: Acf/UpiR8x35BTw1TvizaZ9ioYS2BQACt+lA
- Thread-topic: Variable expansion problem
Thanks for the reply, although it doesn't seem to be working for me. I did the following:
1. Put your code snippet into a file named _expand_literal_param in a directory on my FPATH.
2. Added _expand_literal_param to my list of completers (which doesn't have an entry for _expand); my list is now: zstyle ':completion:*' completer _expand_literal_param _complete _correct _approximate
3. Set the following variable: IDENT="$PF\Citrix\Web Interface\5.0.0\sitemgr.exe -arg foo"
4. Typed $IDENT<TAB>, which expanded to:
C:\\Program\ Files\ \(x86\)\\Citrix\\Web\ Interface\\5.0.0\\sitemgr.exe\ -arg\ foo
(the space between the 2 args is still quoted.). I suspect I'm doing something wrong!
I don't really understand the code, and I'm not sure what you mean by "only kicks in if the entire word matches $<paramname>.", as there is no <paramname> in the code - did you mean it kicks in when the entire param name matches "$IDENT"? Btw, what is the "P" referring to in ${(P)+val}?
I managed to get the effect working by defining the following alias (backslashes were awkward so I used `cygpath' to convert to unix-style paths):
PFu=$(cygpath -u $PF)
alias sss="\\\"$PFu/Citrix/Web Interface/5.0.0/sitemgr.exe\\\" -arg foo"
It seemed unwieldy to invoke it by typing the following (I use Emacs key mappings)
sssMeta-X _expa<TAB>a<TAB><RET>
.. so I've added _expand_alias to my list of completers (just before _complete), so sss now expands as I'd like when I type sss<TAB>. This is OK but now if I type d<TAB> it expands my alias for "d" rather than completing all commands starting with "d".
I think what I really want is to be able to type
Prompt> $SITEMGR -c <TAB>
.. and have it complete to:
Prompt> $SITEMGR -c "WIDest=1:/Citrix/AccessPlatform,Config=Local,XMLService=beanstalk:80"
--- John.
-----Original Message-----
From: Peter Stephenson [mailto:pws@xxxxxxx]
Sent: 25 September 2007 10:01
To: zsh-users@xxxxxxxxxx
Subject: 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
directly.
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):
#autoload
# Expand a parameter literally (no quotation). Only activates if the entire
# word matches a parameter name.
local val="$IPREFIX$PREFIX$SUFFIX$ISUFFIX" expl
[[ $val = \$[[:IDENT:]]## ]] || return 1
val=$val[2,-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