[darcs-devel] darcs patch: bash completion made more robust regarding shell speci...

Guillaume guillaume.outters at free.fr
Tue Dec 28 08:39:25 PST 2004


Le 28 déc. 2004, à 16:26, David Roundy a écrit :

> On Mon, Dec 27, 2004 at 10:02:31PM -0500, Guillaume Outters wrote:
>
>> hunk ./darcs_completion 19
>> +    local IFS=$'\n'
>> hunk ./darcs_completion 21
>> -                   grep "^$cur" | sed 's/:/\\:/g') )
>> +                   grep "^$cur" | sed 's/[: 	$]/\\&/g') )
>
> I'm afraid I don't understand what this is doing.  Could you please 
> explain
> it a bit?

This was primarily for push/pull completion, where the --list-option 
can return repositories with "strange" characters in them (like 
"~/Library/Application Support/darcs/thing-version", which contains a 
space, oh those crazy Mac OS X users!)

First, local IFS=$'\n' is used to tell bash not to split along each 
space, tab or CR, but only on CR; we thus get spaces and tabs correctly 
included in the completion, instead of spliting to two completions 
("~/Library/Application" and "Support/darcs/thing-version").

Then, we adapt the resulting strings to be reusable by bash, by 
replacing any of :, space, tab, and dollar (by the way, I'm noticing 
that I forgot a lot of characters to escape. I just found the 
magnificent printf %q in the bash manual, which I'll try to adapt to 
this case) by a backslash followed by the character itself. If we don't 
do this, in the case where we have two repositories named ~/space in 
there-0.1 and ~/space in there-0.2, the first completion will give us:
bash> darcs push ~/space in there-0.
~/space in there-0.1 ~/space in there-0.2
and we have introduced a space in the command line (if we try to 
recomplete that, it won't find anything, as it doesn't know anything 
starting with "there-0").

Of this explanation, I suppose some bits could go into the detailed 
comment of the patch, before I resubmit it (with the printf solution). 
Which verbosity should I have there (mostly regarding the concrete 
example)?

By the way, while writing this all down, I thought I could do something 
more robust using an IFS of $'\000', "à la" xargs -0, and preparing the 
script to accept the output of a future darcs […] --list-option-0 ("à 
la" find -print0). Who knows, carriage return is not forbidden as a 
filename character…

-- 
Guillaume





More information about the darcs-devel mailing list