Use the current working directory of the foreground process for the *_with_cwd actions that open a new window with the current working directory.

This commit is contained in:
Kovid Goyal 2019-01-03 13:29:52 +05:30
parent c4aeb1adba
commit 718f7e77a1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 31 additions and 10 deletions

View File

@ -13,6 +13,10 @@ Changelog
- Report the current foreground processes as well as the original child process,
when using `kitty @ ls`
- Use the current working directory of the foreground process for the
`*_with_cwd` actions that open a new window with the current working
directory.
- Fix setting :opt:`background_opacity` causing window margins/padding to be slightly
different shade from background (:iss:`1221`)

View File

@ -256,7 +256,7 @@ class Boss:
def new_os_window_with_cwd(self, *args):
w = self.active_window_for_cwd
cwd_from = w.child.pid if w is not None else None
cwd_from = w.child.pid_for_cwd if w is not None else None
self._new_os_window(args, cwd_from)
def add_child(self, window):
@ -855,7 +855,7 @@ class Boss:
def pipe(self, source, dest, exe, *args):
cmd = [exe] + list(args)
window = self.active_window
cwd_from = window.child.pid if window else None
cwd_from = window.child.pid_for_cwd if window else None
def create_window():
return self.special_window_for_cmd(
@ -923,7 +923,7 @@ class Boss:
def new_tab_with_cwd(self, *args):
w = self.active_window_for_cwd
cwd_from = w.child.pid if w is not None else None
cwd_from = w.child.pid_for_cwd if w is not None else None
self._create_tab(args, cwd_from=cwd_from)
def _new_window(self, args, cwd_from=None):
@ -941,7 +941,7 @@ class Boss:
w = self.active_window_for_cwd
if w is None:
return self.new_window(*args)
cwd_from = w.child.pid if w is not None else None
cwd_from = w.child.pid_for_cwd if w is not None else None
self._new_window(args, cwd_from=cwd_from)
def move_tab_forward(self):

View File

@ -205,6 +205,10 @@ class Child:
ans['cmdline'] = cmdline_of_process(pid)
except Exception:
pass
try:
ans['cwd'] = cwd_of_process(pid) or None
except Exception:
pass
return ans
return list(map(process_desc, foreground_processes))
@ -231,3 +235,21 @@ class Child:
return cwd_of_process(self.pid)
except Exception:
pass
@property
def pid_for_cwd(self):
try:
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]
except Exception:
pass
return self.pid
@property
def foreground_cwd(self):
try:
return cwd_of_process(self.pid_for_cwd) or None
except Exception:
pass

View File

@ -10,7 +10,6 @@ from collections import deque
from enum import IntEnum
from itertools import chain
from .child import cwd_of_process
from .config import build_ansi_color_table
from .constants import (
ScreenGeometry, WindowGeometry, appname, get_boss, wakeup
@ -481,11 +480,7 @@ class Window:
@property
def cwd_of_child(self):
# TODO: Maybe use the cwd of the leader of the foreground process
# group in the session of the child process?
pid = self.child.pid
if pid is not None:
return cwd_of_process(pid) or None
return self.child.foreground_cwd or self.child.current_cwd
def pipe_data(self, text, has_wrap_markers=False):
text = text or ''