made cssh also work with ssh config host ids (complete fix)

eg
```sh
cssh monitoring.tunnel
```

fixes [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=4405]
This commit is contained in:
Guillaume Raffy 2026-06-25 16:29:19 +02:00
parent 4d6a14f4e2
commit 34568ed949
1 changed files with 5 additions and 4 deletions

View File

@ -451,7 +451,7 @@ def parse_ssh_config(ssh_config_file_path) -> SshConfig:
def main():
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)
arg_parser = argparse.ArgumentParser('cssh (colored ssh) opens a terminal window with a background color that depends on the fully qualified domain name of the target machine')
arg_parser.add_argument('ssh_target', help='eg root@alambix50.ipr.univ-rennes.fr')
args = arg_parser.parse_args()
@ -459,15 +459,16 @@ def main():
ssh_target = SshTarget(args.ssh_target) # eg 'root@alambix50.ipr.univ-rennes.fr'
ssh_config_file_path: Path = Path(os.getenv('HOME')) / '.ssh' / 'config'
host_real_name = ssh_target.host_id
host_real_name = None
if ssh_config_file_path.exists():
ssh_config = parse_ssh_config(ssh_config_file_path)
hn = ssh_config.get_host_name(ssh_target.host_id)
if hn:
host_real_name = hn
if host_real_name is None:
host_real_name = get_host_real_fqdn(ssh_target.host_id)
logging.debug('host_real_name = %s', host_real_name)
ssh_target.host_id = get_host_real_fqdn(host_real_name)
logging.debug('ssh_target.host_id = %s', ssh_target.host_id)
# AS_ROOT='false'
# if [ "$(echo $@ | grep '^root@' > /dev/null)" ]
@ -512,7 +513,7 @@ def main():
else:
raise NotImplementedError(f'unhandled os : "{os_name}"')
proc = subprocess.run(['make_color.py', ssh_target.host_id, str(color_value), str(color_saturation), 'linux'], check=True, stdout=subprocess.PIPE)
proc = subprocess.run(['make_color.py', host_real_name, str(color_value), str(color_saturation), 'linux'], check=True, stdout=subprocess.PIPE)
bg_color_as_str = proc.stdout.decode('utf8').strip()
match = re.match(r'\((?P<red>[0-9]+), (?P<green>[0-9]+), (?P<blue>[0-9]+)\)', bg_color_as_str)
assert match, f'unexpected color as string: {bg_color_as_str}'