[Bash-completion-devel] _known_hosts is wrong (?)

Freddy Vulto fvulto at gmail.com
Sat Jul 25 07:47:50 UTC 2009

Ildar Mulyukov <ildar <at> users.sourceforge.net> writes:
> $ ping <TAB> error: _known_hosts_real(ping ping ): unprocessed  
> arguments: ping

Hello Ildar,

We're trying to separate the completing function (_known_hosts) from
the helper function (_known_hosts_real) in order to make the helper
function more reusable and less tightly coupled.

The idea was to let `_known_hosts()' pass "$@" to
`_known_hosts_real()' in case code 'out there' relies on the old
behaviour of `_known_hosts'.  This seems impossible however, and
introduced the bug above: _known_hosts() can't know whether it's
accessed via `complete -p' or via a helper call:

    $ foo() { echo \$@: $@; }
    $ complete -F foo bar
    $ bar -a<TAB>$@: bar -a bar  # Completion passes command `bar' as $1
    $ foo -a
    $@: -a                       # Using foo as helper passes `-a' as $1

This is one of the reasons why we want to split the two... 

I modified the backwards compatibility code and updated the comment,
(and added a ping unit test) see also commit 6d31b15:

    # NOTE: Using `_known_hosts' as a helper function and passing
    #       options to `_known_hosts' is deprecated: Use
    #       `_known_hosts_real' instead.
    [ "$1" = -a ] || [ "$2" = -a ] && options=-a
    [ "$1" = -c ] || [ "$2" = -c ] && options="$options -c"
    _known_hosts_real $options "$(_get_cword)"

Thanks for reporting,

Freddy Vulto

More information about the Bash-completion-devel mailing list