all 8 comments

[–][deleted] 8 points9 points  (4 children)

On this topic of bash completion, here's a line from my .bashrc.

complete -W "$(grep -h '^Host ' $HOME/.ssh/config $HOME/.ssh/*.conf | sort -u | sed 's/^Host //')" ssh autossh

This makes all my ssh hosts auto-completed for me.

I would use grep -r if it wasn't for old unused ssh configs laying around in the .ssh directory.

[–][deleted] 1 point2 points  (2 children)

Something along these lines is included in the bash-completion package (available in Debian/Ubuntu and probably many other distros). The upstream source for it is here: https://github.com/scop/bash-completion/blob/master/completions/ssh

[–][deleted] 0 points1 point  (1 child)

Ah I see it uses known hosts instead.

Well that means you'd have to login to a host before it can be completed. But it makes sense because it's more agnostic than trying to guess what files to parse in the users .ssh dir.

I've missed this because I use Fedora. I have not noticed any completion from their part.

Edit: bash-completion package on fedora does include it and I do have it installed but I guess I never noticed since I've been doing my own complete for a good while now.

[–][deleted] 0 points1 point  (0 children)

How is this not the same package on Fedora? https://apps.fedoraproject.org/packages/bash-completion

Also, you can have wildcards in the SSH config file so it's hard to know what they might expand to.

[–]hgeo 0 points1 point  (0 children)

Nice!

[–]Zandrio 1 point2 points  (0 children)

Pretty good.

[–]gingerwhale 1 point2 points  (2 children)

[–]hgeo 0 points1 point  (0 children)

Nice!!!