Solution for: #124: Exclude /etc/hosts from bash_completion

COMP_KNOWN_HOSTS_WITH_HOSTFILE excludes /etc/hosts

2
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

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

  1. 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