[Bash-completion-devel] dd completion not working (was: Fwd: [arch-general] dd and bash_completion)

Freddy Vulto fvulto at gmail.com
Thu Sep 24 19:10:22 UTC 2009


On Thu, Sep 24, 2009 at 6:36 PM, David Paleino <d.paleino at gmail.com> wrote:
> This is due to COMP_WORDBREAKS containing "=":

I guess this bug turns up on bash-4 only?

This can be fixed by adding `=' as an argument to `_get_cword' so that
_get_cword on bash-4 doesn't split words on `='.

Done so in commit f871fe4.

Explanation:

Bash-4 breaks COMP_WORDS by characters listed in COMP_WORDBREAKS:

    $ echo -n "$COMP_WORDBREAKS" | od -abc
    0000000  sp  ht  nl   "   '   >   <   =   ;   |   &   (   :
            040 011 012 042 047 076 074 075 073 174 046 050 072
                 \t  \n   "   '   >   <   =   ;   |   &   (   :
    0000015

whereas bash-3 didn't.  If you use COMP_CWORDS, this is what you get on
bash-4:

    $ dd if=<TAB>
    COMP_CWORD: 2
    COMP_CWORDS:
    0: dd
    1: if
    2: =

Bash-3 returns:

    COMP_CWORD: 1
    COMP_CWORDS:
    0: dd
    1: if=

To reproduce: Create function `_cword' and let it complete `dd'

    _cword() {
       echo
       echo COMP_CWORD: $COMP_CWORD
       echo COMP_CWORDS:
       for ((i=0; i < ${#COMP_WORDS[@]}; i++)); do
           echo $i: "${COMP_WORDS[$i]}"
       done
    }
    complete -F _cword dd

By using _get_cword you can overcome this difference.


Greetings,

Freddy Vulto
http://fvue.nl



More information about the Bash-completion-devel mailing list