3

I've got the "bash-completion" package installed.

ssh completion on the command line (in bash) is working: ssh TAB-TAB will complete past used hosts and ssh -TAB-TAB will complete available ssh options.

However when I search for currently defined completions:

$ complete | grep ssh
complete -F _known_hosts ssh-installkeys
complete -F _service /etc/init.d/ssh

... I find that there's no completion registered for ssh ?!

complete -p ssh
bash: complete: ssh: no completion specification

When I check the ssh completions script under /usr/share/bash-completion/completions/ssh then I see that indeed it does register ssh completions:

$ grep complete /usr/share/bash-completion/completions/ssh | grep ssh | grep -v '^#'
shopt -u hostcomplete && complete -F _ssh ssh slogin autossh sidedoor

So why doesn't the ssh completion show up in complete | grep ssh? How does bash complete the ssh options?

1 Answers1

3

If there is no completion defined for a command (or a function or whatever) then the "default" completer kicks in.

That default completer can be seen here:

$ complete -p -D
complete -F _completion_loader -D

When the bash-completion package is installed, then that will source /usr/share/bash-completion/bash_completion via /etc/bash.bashrc and that will assign the _completion_loader function.

_completion_loader will dynamically load specific completers upon completion request for commands the shell's completer doesn't know about yet (see here).

In the case of ssh, the terminals where I was doing the poking around had not yet loaded the ssh completer and so I was not seeing it with complete | grep ssh or complete -p ssh. It's only at the moment when you press TAB-TAB for the first time that the completer for ssh gets loaded.