Background context: I want the ssh command on the OS X terminal to tab-complete hostnames I use frequently. On Ubuntu, ssh seems smart enough to be able to tab-complete any hostname I have in my ~/.ssh/config file. But OS X does not seem to have this behavior, so I'm trying to manually force tab-completion for some hosts I use very frequently.

If I open up a terminal and run this:

$ complete -W foo.com ssh

Then typing ssh f<tab> will complete into ssh foo.com

Question: when I put such a command in my ~/.bash_profile, it no longer works. Why?

I'm sure the ~/.bash_profile is being executed, as I have other things in there (prompt configs, etc) which are taking effect in my terminal session.

Shouldn't putting things in my ~/.bash_profile be the equivalent of automatically executing those commands in the terminal on session startup? It's as if the complete command runs inside a context that's lost, while other things persist (such as my PS1 prompt setting.)

Thanks for any insight here, bash experts!


Using complete to list my configuration showed me my mistake. I'm using multiple statements, ie:

complete -W foo.com ssh; complete -W bar.com ssh

And only the last one takes effect (each one replaces the one before it). So, I need to put them all in one command, ie:

complete -W 'foo bar' ssh

So this question is not about ~/.bash_profile, it's about understanding the right way to use "complete"

  • I'm voting to close this question as off-topic because Unable to Reproduce (typo)
    – jww
    Oct 10 '18 at 19:37

What happens if you try:

complete | grep ssh

does an entry show up?

I would recommend installing the bash-completion package.

  • Thanks for the pointer. Using complete to list my configuration showed me my mistake. I updated my question and closed this out. Thanks! Jun 30 '10 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.