From 44baeb692468b9a375bb9de5a896f1b725684c49 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 24 Feb 2022 13:35:23 +0530 Subject: [PATCH] Run login_shell detection tests with all available shells --- kitty_tests/ssh.py | 26 +++++++++++++------------- shell-integration/ssh/bootstrap.sh | 10 +++++++--- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/kitty_tests/ssh.py b/kitty_tests/ssh.py index 0e2ed9c6b..2027f0447 100644 --- a/kitty_tests/ssh.py +++ b/kitty_tests/ssh.py @@ -60,23 +60,23 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77) self.assertTrue(methods) import pwd expected_login_shell = pwd.getpwuid(os.geteuid()).pw_shell + all_possible_sh = tuple(sh for sh in ('dash', 'zsh', 'bash', 'posh', 'sh') if shutil.which(sh)) for m in methods: - with self.subTest(method=m): - pty = self.check_bootstrap('sh', tdir, extra_exec=f'{m}; echo "$login_shell"; exit 0', SHELL_INTEGRATION_VALUE='') - self.assertIn(expected_login_shell, pty.screen_contents()) + for sh in all_possible_sh: + with self.subTest(sh=sh, method=m): + pty = self.check_bootstrap(sh, tdir, extra_exec=f'{m}; echo "$login_shell"; exit 0', SHELL_INTEGRATION_VALUE='') + self.assertIn(expected_login_shell, pty.screen_contents()) ok_login_shell = '' - for sh in ('dash', 'zsh', 'bash', 'posh', 'sh'): - q = shutil.which(sh) - if q: - if sh == 'bash' and not bash_ok(): + for sh in all_possible_sh: + if sh == 'bash' and not bash_ok(): + continue + for login_shell in ('', 'fish', 'zsh', 'bash'): + if (login_shell and not shutil.which(login_shell)) or (login_shell == 'bash' and not bash_ok()): continue - for login_shell in ('', 'fish', 'zsh', 'bash'): - if (login_shell and not shutil.which(login_shell)) or (login_shell == 'bash' and not bash_ok()): - continue - ok_login_shell = login_shell - with self.subTest(sh=sh, login_shell=login_shell), tempfile.TemporaryDirectory() as tdir: - self.check_bootstrap(sh, tdir, login_shell) + ok_login_shell = login_shell + with self.subTest(sh=sh, login_shell=login_shell), tempfile.TemporaryDirectory() as tdir: + self.check_bootstrap(sh, tdir, login_shell) # check that turning off shell integration works if ok_login_shell in ('bash', 'zsh'): for val in ('', 'no-rc'): diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index 3d4744603..a69cc575e 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -105,12 +105,16 @@ detect_python() { return 0; } +parse_passwd_record() { + printf "%s" "$(grep -o '[^:]*$')" +} + using_getent() { cmd=$(command -v getent) if [ -n "$cmd" ]; then output=$($cmd passwd $USER 2>/dev/null) if [ $? = 0 ]; then - login_shell=$(echo $output | grep -o '[^:]*$'); + login_shell=$(echo $output | parse_passwd_record); if login_shell_is_ok; then return 0; fi fi fi @@ -122,7 +126,7 @@ using_id() { if [ -n "$cmd" ]; then output=$($cmd -P $USER 2>/dev/null) if [ $? = 0 ]; then - login_shell=$(echo $output | grep -o '[^:]*$'); + login_shell=$(echo $output | parse_passwd_record); if login_shell_is_ok; then return 0; fi fi fi @@ -134,7 +138,7 @@ using_passwd() { if [ -n "$cmd" ]; then output=$($cmd "^$USER:" /etc/passwd 2>/dev/null) if [ $? = 0 ]; then - login_shell=$(echo $output | grep -o '[^:]*$'); + login_shell=$(echo $output | parse_passwd_record); if login_shell_is_ok; then return 0; fi fi fi