1
votes

I use bash completion all the time to save typing. However there is an oddity I am unable to figure out how to fix on OSX.

If I install bash-completion using Homebrew (brew install bash-completion) and set it up in .bashrc, the tab key will no longer complete environment variables. Without this installed, environment variable completion works as expected.

For example, I have shortcuts for all my SSH accounts for clients... instead of typing ssh [email protected] I can just type ssh $SSHCRAZY which is much easier to remember.

Expected behavior: In the built-in bash in OSX I can type ssh $SSHC and hit tab and it completes to the full command as expected. This is what I want.

Observed behavior: In bash using the homebrew bash-completion additions, hitting tab has no effect for environment variables.

Note: All other extensions added by the bash-completion project are desired (git command completion, etc). I don't want to uninstall it, I just want it to also work with environment variables.

Thanks in advance for any help!

2

2 Answers

4
votes

You might consider using an SSH config file (~/.ssh/config) to set up your SSH shortcuts instead of using environment variables. You could put into that file:

Host crazy
    HostName somecrazydomain.com
    User myuser

Then you can just type ssh crazy.

3
votes

I guess bash-completion must have defined completion rule for ssh. So try add the -o bashdefault option in your .bashrc. For example, if complete -p ssh output like this:

# complete -p ssh
complete -F _func ssh
#

then you can add this to your .bashrc (or .bash_profile):

complete -F _func -o bashdefault ssh

or

eval "$(complete -p ssh | sed 's/ssh$/-o bashdefault ssh/')"