I just installed the homebrew package bash_completion, hoping to get completion on my SSH commands. Unfortunately, I also use my /etc/hosts file as an ad blocker. This results in bash completion completing my ssh hostnames with a ton of ad servers that I put into /etc/hosts, instead of just the few in ~/.ssh/known_hosts that I actually use.
I need a way to exclude these /etc/hosts matches from bash_completion for SSH.
COMP_KNOWN_HOSTS_WITH_HOSTFILE excludes /etc/hosts
- yliu on October 29, 2012, 10:47 PM UTC
After digging through the code, it seems that setting the environment variable COMP_KNOWN_HOSTS_WITH_HOSTFILE to an empty value will exclude /etc/hosts from bash completion on SSH. This leaves just the known_hosts file as the source for completions.
On homebrew, for example, adding the line COMP_KNOWN_HOSTS_WITH_HOSTFILE="" before the bash source include
will exclude the misc. matches from completion.
On homebrew, for example, adding the line COMP_KNOWN_HOSTS_WITH_HOSTFILE="" before the bash source include
if [ -f $(brew --prefix)/etc/bash_completion ]; then
COMP_KNOWN_HOSTS_WITH_HOSTFILE='' # this suppresses use of /etc/hosts
. $(brew --prefix)/etc/bash_completion
fi
will exclude the misc. matches from completion.
Comments
The same result can be accomplished by adding
export COMP_KNOWN_HOSTS_WITH_HOSTFILE=""
to your .bashrc, rather than modifying the bash_completion source.
— sean_the_bean on June 20, 2016, 07:52 PM UTC