Merge branch 'fix/bash-ssh-hostname-detection' of https://github.com/M-Hassan-Raza/kitty

This commit is contained in:
Kovid Goyal 2026-08-14 07:58:18 +05:30
commit f29665f601
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 20 additions and 1 deletions

View file

@ -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:

View file

@ -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