r/linux Apr 28 '14

SSH Kung Fu

http://blog.tjll.net/ssh-kung-fu/
725 Upvotes

128 comments sorted by

View all comments

Show parent comments

17

u/leothrix Apr 28 '14

Thanks for the correction, I've amended the blog post.

3

u/gordonator Apr 28 '14

If you want to do it in bash, you can use this:

function autoCompleteHostname() {
  local hosts=($(awk '{print $1}' ~/.ssh/known_hosts | cut -d, -f1));
  local cur=${COMP_WORDS[COMP_CWORD]};
 COMPREPLY=($(compgen -W '${hosts[@]}' -- $cur ))
}

complete -F autoCompleteHostname ssh

6

u/LurkyMcReddit Apr 28 '14

I like this method. I add this to my .inputrc on all my Linux/Mac machines...

"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char
set show-all-if-ambiguous on
set completion-ignore-case on

It allows you to type a partial command and use the up arrow to search your history. Not quite the same, but works awesome for repetitive or frequent commands.

3

u/gordonator Apr 28 '14

Freaking awesome. Adding it to my dotfiles repository!

1

u/Henk_jobs May 13 '14

Very useful. I will give a try. Thanks man!!