Skip to content

Instantly share code, notes, and snippets.

@nuBacuk
Last active July 17, 2020 10:44
Show Gist options
  • Select an option

  • Save nuBacuk/b21e95504e26059eaaf29decd9ce55ed to your computer and use it in GitHub Desktop.

Select an option

Save nuBacuk/b21e95504e26059eaaf29decd9ce55ed to your computer and use it in GitHub Desktop.
bash ssh autocomplete
file: ~/.bashrc
. /etc/bash_completion.d/ssh
file: .ssh/config
Host *
HashKnownHosts no
StrictHostKeyChecking no
file: /etc/bash_completion.d/ssh
__complete_ssh_host() {
local KNOWN_FILE=~/.ssh/known_hosts
if [ -r $KNOWN_FILE ] ; then
local KNOWN_LIST=`cut -f 1 -d ' ' $KNOWN_FILE | cut -f 1 -d ',' | grep -v '^[0-9[]'`
fi
local PARTIAL_WORD="${COMP_WORDS[COMP_CWORD]}";
COMPREPLY=( $(compgen -W "$KNOWN_LIST$IFS$CONFIG_LIST" -- "$PARTIAL_WORD") )
return 0
}
complete -F __complete_ssh_host ssh
complete -f -F __complete_ssh_host scp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment