From bf18c2b8c1cf072cfe4c7624dbbefb843ed4905c Mon Sep 17 00:00:00 2001 From: Hassan Raza Date: Thu, 13 Aug 2026 07:55:42 +0500 Subject: [PATCH] Fix Bash SSH hostname detection --- kitty_tests/shell_integration.py | 19 +++++++++++++++++++ shell-integration/bash/kitty.bash | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/kitty_tests/shell_integration.py b/kitty_tests/shell_integration.py index 90b8a76cb..a87f1317c 100644 --- a/kitty_tests/shell_integration.py +++ b/kitty_tests/shell_integration.py @@ -178,6 +178,25 @@ class ShellIntegration(BaseTest): self.assertEqual(cp.returncode, 0, cp.stderr.decode()) self.assertEqual(cp.stdout.decode() != 'original', has_command_hook) + @unittest.skipUnless(bash_ok(), 'bash not installed, too old, or debug build') + def test_bash_ssh_hostname_fallback(self): + if self.with_kitten: + return + integration_script = os.path.join(shell_integration_dir, 'bash', 'kitty.bash') + command = 'PS1="prompt> "; source "$KITTY_BASH_INTEGRATION"; _ksi_prompt_command; printf %s "${PS1@P}"' + with tempfile.TemporaryDirectory() as home_dir: + home_dir = os.path.realpath(home_dir) + who = os.path.join(home_dir, 'who') + with open(who, 'w') as f: + f.write("#!/bin/sh\nprintf '%s\\n' 'user pts/0 (192.0.2.1)'\n") + os.chmod(who, 0o755) + env = basic_shell_env(home_dir) + env['KITTY_BASH_INTEGRATION'] = integration_script + env['PATH'] = os.pathsep.join((home_dir, env['PATH'])) + cp = subprocess.run(['bash', '--noprofile', '--norc', '-ic', command], cwd=home_dir, env=env, capture_output=True) + self.assertEqual(cp.returncode, 0, cp.stderr.decode()) + self.assertIn(': ~\x07', cp.stdout.decode()) + @unittest.skipUnless(shutil.which('fish'), 'fish not installed') def test_fish_sudo_parser(self): if self.with_kitten: diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 8506afe9e..67acd91e6 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -236,7 +236,7 @@ _ksi_main() { # connected to most SSH servers # or use ssh kitten to connected to some SSH servers that do not set SSH_TTY _ksi_prompt[hostname_prefix]="\h: " - elif [[ -n "$(builtin command -v who)" && "$(builtin command who -m 2> /dev/null)" =~ "\([a-fA-F.:0-9]+\)$" ]]; then + elif [[ -n "$(builtin command -v who)" && "$(builtin command who -m 2> /dev/null)" =~ \([a-fA-F.:0-9]+\)$ ]]; then # the shell integration script is installed manually on the remote system # the environment variables are cleared after sudo # OpenSSH's sshd creates entries in utmp for every login so use those