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
ssh f<tab> will complete into
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"