From 7448789951f26213e2ec7effde21cd99b2dca651 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 8 Feb 2022 20:30:00 +0530 Subject: [PATCH] Improve CWD detection when there are multiple foreground processes in the TTY process group --- docs/changelog.rst | 2 ++ kitty/child.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 6ec91e9cf..9dfcb6ac6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -86,6 +86,8 @@ Detailed list of changes - Fix a regression in the previous release that broke :opt:`active_tab_foreground` (:iss:`4620`) +- Improve CWD detection when there are multiple foreground processes in the TTY process group + - ssh kitten: Fix location of generated terminfo files on NetBSD (:iss:`4622`) - A new action to clear the screen up to the line containing the cursor, see diff --git a/kitty/child.py b/kitty/child.py index a8b990fc9..f56b3de47 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -344,8 +344,18 @@ class Child: assert self.child_fd is not None pgrp = os.tcgetpgrp(self.child_fd) foreground_processes = processes_in_group(pgrp) if pgrp >= 0 else [] - if len(foreground_processes) == 1: - return foreground_processes[0] + if foreground_processes: + # there is no easy way that I know of to know which process is the + # foreground process in this group from the users perspective, + # so we assume the one with the highest PID is as that is most + # likely to be the newest process. This situation can happen + # for example with a shell script such as: + # #!/bin/bash + # cd /tmp + # vim + # With this script , the foreground process group will contain + # both the bash instance running the script and vim. + return max(foreground_processes) return self.pid @property