Use the launch time argv for cmdline on macOS

This commit is contained in:
Kovid Goyal 2018-01-08 13:07:06 +05:30
parent 464c7a80e2
commit c6d10c6a23
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 17 additions and 20 deletions

View File

@ -78,3 +78,17 @@ class Child:
os.close(stdin_read_fd) os.close(stdin_read_fd)
fast_data_types.thread_write(stdin_write_fd, stdin) fast_data_types.thread_write(stdin_write_fd, stdin)
return pid return pid
@property
def cmdline(self):
try:
return cmdline_of_process(self.pid)
except Exception:
return list(self.argv)
@property
def current_cwd(self):
try:
return cwd_of_process(self.pid)
except Exception:
pass

View File

@ -8,7 +8,6 @@ import weakref
from collections import deque from collections import deque
from enum import Enum from enum import Enum
from .child import cmdline_of_process, cwd_of_process
from .config import build_ansi_color_table, parse_send_text_bytes from .config import build_ansi_color_table, parse_send_text_bytes
from .constants import ( from .constants import (
ScreenGeometry, WindowGeometry, appname, get_boss, wakeup ScreenGeometry, WindowGeometry, appname, get_boss, wakeup
@ -109,19 +108,11 @@ class Window:
return 'Window(title={}, id={})'.format(self.title, self.id) return 'Window(title={}, id={})'.format(self.title, self.id)
def as_dict(self): def as_dict(self):
try:
cwd = cwd_of_process(self.child.pid)
except Exception:
cwd = None
try:
cmdline = cmdline_of_process(self.child.pid)
except Exception:
cmdline = None
return dict( return dict(
id=self.id, id=self.id,
title=self.override_title or self.title, title=self.override_title or self.title,
pid=self.child.pid, pid=self.child.pid,
cwd=cwd, cmdline=cmdline cwd=self.child.current_cwd or self.child.cwd, cmdline=self.child.cmdline
) )
def matches(self, field, pat): def matches(self, field, pat):
@ -132,17 +123,9 @@ class Window:
if field == 'title': if field == 'title':
return pat.search(self.override_title or self.title) is not None return pat.search(self.override_title or self.title) is not None
if field in 'cwd': if field in 'cwd':
try: return pat.search(self.child.current_cwd or self.child.cwd) is not None
cwd = cwd_of_process(self.child.pid)
except Exception:
return False
return pat.search(cwd) is not None
if field == 'cmdline': if field == 'cmdline':
try: for x in self.child.cmdline:
cmdline = cmdline_of_process(self.child.pid)
except Exception:
return False
for x in cmdline:
if pat.search(x) is not None: if pat.search(x) is not None:
return True return True
return False return False