Answers:
您可以bash-completion通过brew安装来启用bash shell完成:
brew install bash-completion然后将以下内容添加到您的~/.bash_profile:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi(编辑:brew tap homebrew/completions自2018年起不推荐使用。)
我认为您Mac的外壳是bash。
您需要完成ssh命令,有关更多详细信息,请阅读 man complete
_complete_ssh_hosts ()
{
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
                        cut -f 1 -d ' ' | \
                        sed -e s/,.*//g | \
                        grep -v ^# | \
                        uniq | \
                        grep -v "\[" ;
                cat ~/.ssh/config | \
                        grep "^Host " | \
                        awk '{print $2}'
                `
        COMPREPLY=( $(compgen -W "${comp_ssh_hosts}" -- $cur))
        return 0
}
complete -F _complete_ssh_hosts ssh别忘了您需要source文件来获取要在终端中加载的新命令。或者您可以将此代码放在.bash_profile中
comp_ssh_hosts=$(awk -F , 'FNR== NR && ! /^#|\[/ {field = $1} FNR != NR && /^Host / {field = $2} {hosts[field]} END {for (host in hosts) {print host}' "$HOME/.ssh/known hosts" "$HOME/.ssh/config")
                    将以下内容复制/粘贴到~/.bash_profile:
complete -o default -o nospace -W "$(/usr/bin/env ruby -ne 'puts $_.split(/[,\s]+/)[1..-1].reject{|host| host.match(/\*|\?/)} if $_.match(/^\s*Host\s+/);' < $HOME/.ssh/config)" scp sftp ssh然后,您需要重新启动终端或键入source ~/.bash_profile(请注意,后者仅在您当前的选项卡中有效)。
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion。您能详细说明应该使用哪个版本(或您的哪个版本),为什么?