Permalink
Browse files

Adding intelligent ssh host auto-completion (thx to @dariusk for the …

…idea).
  • Loading branch information...
1 parent 0fd8651 commit 0a910021d44b9b4e09a9e33643f3bdca2dfc75d6 @cowboy committed Feb 3, 2012
Showing with 5 additions and 0 deletions.
  1. +5 −0 source/50_misc.sh
View
@@ -11,3 +11,8 @@ export GREP_OPTIONS='--color=auto'
function titlebar() {
echo -n $'\e]0;'"$*"$'\a'
}
+
+# SSH auto-completion based on entries in known_hosts.
+if [[ -e ~/.ssh/known_hosts ]]; then
+ complete -o default -W "$(cat ~/.ssh/known_hosts | sed 's/[, ].*//' | sort | uniq | grep -v '[0-9]')" ssh
+fi
@mathiasbynens

mathiasbynens Jun 12, 2012

You might want to use these values to autocomplete scp and sftp too.

I’ve been using the following in my dotfiles:

[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2)" scp sftp ssh
@cowboy

cowboy Jun 12, 2012

Owner

Done in b76ee2d, thanks!

0 comments on commit 0a91002

Please sign in to comment.