Skip to content

Instantly share code, notes, and snippets.

@ogrrd
Created October 4, 2013 08:26
Show Gist options
  • Save ogrrd/6822713 to your computer and use it in GitHub Desktop.
Save ogrrd/6822713 to your computer and use it in GitHub Desktop.
Tab out your SSH config or known hosts!

Git info in your bash prompt

Edit ~/.bash_profile and add the following

# ssh
if [ -f ~/.bash_ssh ]; then
        . ~/.bash_ssh
fi

Create ~/.bash_ssh and add the following

_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

Make it happen

Tell your current terminal to use it now

$ source ~/.bash_profile
@philippe271268
Copy link

Very nice thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment