Skip to content

feat(completion): support for SSH hosts#195

Open
Sporif wants to merge 1 commit intonix-community:mainfrom
Sporif:feat-ssh-host-completion
Open

feat(completion): support for SSH hosts#195
Sporif wants to merge 1 commit intonix-community:mainfrom
Sporif:feat-ssh-host-completion

Conversation

@Sporif
Copy link
Collaborator

@Sporif Sporif commented Feb 23, 2026

Retrieve the hosts from the hosts file, SSH config files, and SSH known_hosts files. Also add a setting to allow users to disable hosts file completion in case it contains too many hosts.

The implementation copies _comp_compgen_known_hosts__impl from bash-completion as much as possible. But some parts are intentionally left out, e.g. ssh2 config paths, avahi-browse, ruptime. I believe it also improves upon the ssh config parsing since the lists of hosts from nixos-cli is more correct, at least on my system.

I would use the ssh_config pkg but I'm not sure how to recursively get all hosts, due to some unexported fields. It's probably why a PR was made to add a GetHosts function. So instead of using a fork I have implemented partial ssh config parsing, which has been very fun.

Closes #186.

@Sporif Sporif force-pushed the feat-ssh-host-completion branch from 7c036f7 to 2b95fc7 Compare February 25, 2026 16:46
@water-sucks
Copy link
Collaborator

water-sucks commented Mar 1, 2026

While I do appreciate the time taken for this, it does seem like an awful lot of code to have to introduce that we would have to maintain ourselves, just for SSH config parsing.

I'm open to including it for now, but we may want to pivot to a more battle-tested approach later on because I am sure we may run into issues in the future when users with more complex SSH configurations start to use it.

Also, FYI there is already precedent to use forked packages here, which I use for go-systemd for adding some extra systemd dbus methods, so i don't particularly mind if we introduce a new dependency for this completion if things aren't getting merged upstream, especially since the ssh_config dependency you mention itself has zero transitive ones. Let me know what your thoughts are on this and I'll review the code afterwards.

@Sporif Sporif force-pushed the feat-ssh-host-completion branch from 2b95fc7 to b7a2904 Compare March 2, 2026 19:58
@Sporif
Copy link
Collaborator Author

Sporif commented Mar 2, 2026

Ok, you convinced me to create a fork for ssh_config and use the hostsfile pkg for the hosts file. I also added user@hosts completion.

@Sporif Sporif marked this pull request as ready for review March 2, 2026 20:04
@Sporif Sporif force-pushed the feat-ssh-host-completion branch from b7a2904 to 5f0c030 Compare March 2, 2026 20:22
Retrieve the hosts from the hosts file, SSH config files, and SSH known_hosts
files. Also add a setting to allow users to disable hosts file completion
in case it contains too many hosts.
@Sporif Sporif force-pushed the feat-ssh-host-completion branch from 5f0c030 to 9976d3e Compare March 3, 2026 16:35
@Sporif Sporif changed the title feat(completion): add SSH host completion feat(completion): support for SSH hosts Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

completion: support for SSH hosts

2 participants