SSH command should autocomplete hosts from ~/.ssh/config
Closed this issue ยท 4 comments
-
Host completion from
~/.ssh/config
is not present. -
Invalid hostname entries (for other users)
~/Code/__dotfiles [ master: โ ] 25m ยฑ โฒ ssh ๐ฅ [22:28:27] ๐ [53%] Guest family MacBookAir github.com root heroku.com nikhgupta server.wickeddevelopers.com ....
As per ohmyzsh/ohmyzsh#2737, this is an issue with the ZSH completion for hosts itself. For the time being, entries can be manually added to /etc/hosts
(hackish).
Also, considering that ~/.ssh/config
holds a very minimum number of hosts as compared to ~/.ssh/known_hosts
, this issue is not important.
Note that, host completion is still present, though, invisible. That is, for a host entry with name wdev
, and wickeddevelopers.com
being present in /etc/hosts
, pressing ssh w<tab>
will complete to ssh wickeddevelopers.com
, but pressing ssh wd<tab>
will complete to ssh wdev
.
Not sure about why SSH completion will provide other usernames in the system for completion. Will review this issue, once the above issue from OMZ repo is resolved.
@nikhgupta I disagree on the importance. You observed that there will be only a few entries in ~/.ssh/config
and thus completing them is not important. My humble opinion is that the opposite is true: because there are only few entries in ~/.ssh/config
, these will tend to be ones that are important to the user, so completing on them is highly important.
Of course, you can say that the user can just use Host a
, Host b
, ..., Host z
in ~/.ssh/config
and then connecting to any of these 26 hosts is very quick without requiring completion at all. But it feels like cheating to me.
At least I connect to the hosts in ~/.ssh/config
all the time, and to other hosts seldom.
@kgrossjo I agree with you.
Manually defined values should take precedence over automatically added ones. The known_hosts
file potentially contains many once off connections that should really not be considered before ~/.ssh/config
.
Editing /etc/hosts
is a pretty messy hack.
My own ~/.ssh/config
has 30+ hosts defined. Mostly AWS instances.
The aliases follow a normal package/namespace convention so I'd hoped I could very quickly auto-complete through the levels (<company>.<product>.<purpose>.<environment>
).
Instead the first suggestion is almost always an entire AWS DNS entry or ElasticBeanstalk URL and rarely the server I was trying to get to. This would not be so bad if the matches from all sources were compiled together but the incorrect matches from known_hosts
are all that I get offered.
My prompt gets replaced with the entire wrong URI and I have to remove the entire thing to attempt it again making sure that I type out enough characters that an overlap or incorrect match cannot happen again.