[Bash-completion-devel] ./current r1326: Improved strace completion, undefined _command_offset() found.
Guillaume Rousse
Guillaume.Rousse at inria.fr
Thu Feb 5 18:46:18 UTC 2009
David Paleino a écrit :
> Hello,
>
> On Thu, 05 Feb 2009 11:15:13 +0100, David Paleino wrote:
>
>> ------------------------------------------------------------
>> revno: 1326
>> committer: David Paleino <d.paleino at gmail.com>
>> branch nick: current
>> timestamp: Thu 2009-02-05 11:15:13 +0100
>> message:
>> Improved strace completion, undefined _command_offset() found.
>> modified:
>> to_review/strace
>>
>> === modified file 'to_review/strace'
>> --- a/to_review/strace 2009-01-19 20:51:24 +0000
>> +++ b/to_review/strace 2009-02-05 10:15:13 +0000
>> [..]
>> @@ -25,6 +25,7 @@
>> done
>>
>> if [ $offset -gt 0 ]; then
>> + # FAIL: _command_offset is not defined anywhere. Guillame?
>> _command_offset $offset
>> else
>
> Guillaume, is this a Mandriva-specific helper?
Yes. More precisely, this is the result of a patch of mine splitting
_command function in two part:
_command only tries to identify the context, meaning where does the
wrapping command stop, and where does the wrapped command start, using
the same naive algorithm: the first non-option word on the command line
is supposed to be the wrapped command. It then calls _command_offset
with the specific offset, as a words numer
_command_offset takes care of rewriting the context using provided
offset (rewriting COMP_CWORDS array, mostly), before calling wrapped
command completion function
This rewrite allows to use better context identification algorithm in
some completion function. For instance, some strace options takes args,
and would be confused with wrapped command. And it doesn't change
anything to global _command call behaviour, keeping it compatible with
existing completions.
The initial patch vs Ian's version of _command can be found at
http://svn.mandriva.com/cgi-bin/viewvc.cgi/packages/cooker/bash-completion/releases/20060301/23mdv2009.0/SOURCES/bash-completion-20060301-better-command-completion.patch
The updated version, vs current trunk, is at
http://svn.mandriva.com/svn/packages/cooker/bash-completion/current/SOURCES/bash-completion-20090108-better-command-completion.patch
However, it is broken :(
I tried yesterday to fix it, so as to merge it, but I couldn't succeed
understanding current implementation of _command function. In
particular, I'm a bit confused by the fact the context is first modified
in the initial loop (while [ -z $done ] ; do...) through
_remove_comp_word function, then again just before calling wrapped
command completion.
Incidentally, I also found current implementation has troubles in some
scenarios. For instance, try this:
[guillaume at oberkampf bash-completion]$ sudo rpm -q sed: -e expression
#1, char 5: unterminated `s' command
When debugging, the following trace shows the error happen in
_rpm_installed_packages() function:
+ COMPREPLY=($( sed -ne
's|^\('$cur'[^[:space:]]*\)-[^[:space:]-]\+-[^[:space:]-]\+\.rpm$|\1|p'
/var/log/rpmpkgs ))
++ sed -ne 's|^\('
'[^[:space:]]*\)-[^[:space:]-]\+-[^[:space:]-]\+\.rpm$|\1|p'
/var/log/rpmpkgs
sed: -e expression #1, char 5: unterminated `s' command
This result of the function being called with the cur variable set to "
" (a space) instead of "", which in turn results of the _get_cword
return value being strangely interpreted as a space, even when printing
a null string:
+ COMPREPLY=()
++ _get_cword
++ [[ 0 -eq 0 ]]
++ printf %s ''
+ cur=' '
+ prev=-q
+ nodig=
+ nosig=
More information about the Bash-completion-devel
mailing list