[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash tab variable expansion question?

From: Martin von Gagern
Subject: Re: bash tab variable expansion question?
Date: Mon, 05 Sep 2011 08:05:54 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110831 Thunderbird/6.0

On -10.01.-28163 20:59, Chet Ramey wrote:
>> Bash-4.2 tries to leave what the
>> user typed alone, but that leads to an inherently ambiguous situation:
>> when do you quote the `$' in a filename (or, in this case, a directory
>> name)?  It could be a shell variable, and it could be a character in
>> the filename.

I'm not sure I'd EVER want completion to escape a $. If I want a
variable, I'll type $, either by itself or inside double quotation
marks. If I want a $ included in a file name, then I'll type \$ or
enclose it in single quotation marks. The above I'd do even for partial
file names. So if bash sees an unquoted $, then I'd call it a variable,
and no ambiguity involved.

> That is the problem, in a nutshell.  I posted a partial patch at the
> end of March that applied a heuristic to avoid quoting variable
> expansions in most cases, but there was no way to get the bash-4.1
> behavior back.

Can you explain these heuristics?

> I am soliciting feedback on this iteration.
> Please try the new option (`direxpand') and let me know if it's missing 
> anything.

The option works, as far as I can see.
"ls $HOM" completes to "ls $HOME " instead of "ls $HOME/", though.

The heuristics apparently don't work well with programmatic completion.
With _longopt <http://tinyurl.com/3va3hyz > from the debian bashcomp
project set up for ls, I get "\$HOME/.bash" as the completion for
"$HOME/.bash". And I get no completion at all for "ls $HOM", probably
because there is no dir of that name.

Can we do the following for programmatic completion?
1. If the insertion point is at a variable reference, and the
   referenced variable does not exist, then complete variable name
   without delegating to programmatic completion
2. Otherwise, store the original String for each word
3. Perform variable expansion for each word
4. Perform completion on the expanded words
5. In the completed words, search for the expanded but uncomleted
   strings from 3. and replace them with the unexpanded forms from 2.

I'm not sure what behaviour I'd expect if the variable contains several
words. Don't care too much for that case, so I'll be happy with any

 Martin von Gagern

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]