-
-
Notifications
You must be signed in to change notification settings - Fork 118
Description
Problem
Currently, the ssh-hosts channel provides a way to list configured SSH hosts as they appear in the main $HOME/.ssh/config file. However, not all hosts need to be listed in said config. With the use of the `Include keyword, users can link other configs defining other hosts.
I personally use two different configs on most hosts: one config that I sync across hosts and a local config that only makes sense for a single host.
Feature
It'd be nice for the channel to consider (at least) one level of Includes, although it would make most sense if it could be any arbitrary chain.
This might be a bit out of scope for the ssh-hosts channel but this would make it more complete in my opinion.
Examples
Given this $HOME/.ssh/config file:
Include ~/.ssh/local_config
Host foo
Hostname foo
User foo
And this $HOME/.ssh/local_config file:
Host bar
Hostname bar
User bar
Would make the channel display like so:
Additional context
Here is a pretty verbose attempt at listing the hosts in the first level of Includes (without a preview):
command = """
host_finder () { grep -E '^Host(name)? ' "$1" | tr -s ' ' | cut -d ' ' -f 2 - | tr ' ' '\n' | grep -v '^$'; }
host_finder "$HOME/.ssh/config"
while IFS= read -r inc; do
host_finder "${inc//\\~/$HOME}"
done < <( grep -E '^Include ' "$HOME/.ssh/config" | tr -s ' ' | cut -d ' ' -f 2 - )
"""But this is already pretty awkward as it assumes the Includes use absolute paths, and doesn't support any kind of globbing.
Some more recent versions of SSH do support a -G flag that prints the config after SSH has parsed it but that also seems unreliable.