Allow specifying multiple matching hostnames

This commit is contained in:
Kovid Goyal 2022-03-04 07:23:35 +05:30
parent 3f3efab221
commit 499b30d175
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 8 additions and 7 deletions

View File

@ -19,7 +19,8 @@ defconf = os.path.join(config_dir, 'ssh.conf')
def options_for_host(hostname: str, per_host_opts: Dict[str, SSHOptions]) -> SSHOptions: def options_for_host(hostname: str, per_host_opts: Dict[str, SSHOptions]) -> SSHOptions:
import fnmatch import fnmatch
matches = [] matches = []
for pat, opts in per_host_opts.items(): for spat, opts in per_host_opts.items():
for pat in spat.split():
if fnmatch.fnmatchcase(hostname, pat): if fnmatch.fnmatchcase(hostname, pat):
matches.append(opts) matches.append(opts)
if not matches: if not matches:

View File

@ -26,12 +26,12 @@ agr('host', 'Host environment') # {{{
opt('hostname', '*', option_type='hostname', opt('hostname', '*', option_type='hostname',
long_text=''' long_text='''
The hostname the following options apply to. A glob pattern to match multiple The hostname the following options apply to. A glob pattern to match multiple
hosts can be used. When not specified options apply to all hosts, until the hosts can be used. Multiple hostnames can also be specified separated by spaces.
When not specified options apply to all hosts, until the
first hostname specification is found. Note that the hostname this matches first hostname specification is found. Note that the hostname this matches
against is the hostname used by the remote computer, not the name you pass against is the hostname used by the remote computer, not the name you pass
to SSH to connect to it. If you wish to include the same configuration for many to SSH to connect to it. If you wish to include the same basic configuration for many
different hosts, you can do so with the :code:`include` directive (see :doc:`conf`), different hosts, you can do so with the :code:`include` directive (see :doc:`conf`).
so that you need only two lines per host.
''') ''')
opt('+copy', '', option_type='copy', add_to_default=False, long_text=f''' opt('+copy', '', option_type='copy', add_to_default=False, long_text=f'''