A working implementation of cwd_of_process for FreeBSD
This commit is contained in:
parent
c9ef4aa8c8
commit
587f44ad4e
@ -7,12 +7,15 @@ import sys
|
||||
from collections import defaultdict
|
||||
from contextlib import contextmanager, suppress
|
||||
from typing import (
|
||||
DefaultDict, Dict, Generator, List, Optional, Sequence, Tuple, TYPE_CHECKING
|
||||
TYPE_CHECKING, DefaultDict, Dict, Generator, List, Optional, Sequence,
|
||||
Tuple
|
||||
)
|
||||
|
||||
import kitty.fast_data_types as fast_data_types
|
||||
|
||||
from .constants import is_macos, kitty_base_dir, shell_path, terminfo_dir
|
||||
from .constants import (
|
||||
is_freebsd, is_macos, kitty_base_dir, shell_path, terminfo_dir
|
||||
)
|
||||
from .types import run_once
|
||||
from .utils import log_error, which
|
||||
|
||||
@ -48,6 +51,15 @@ else:
|
||||
with open(f'/proc/{pid}/cmdline', 'rb') as f:
|
||||
return list(filter(None, f.read().decode('utf-8').split('\0')))
|
||||
|
||||
if is_freebsd:
|
||||
def cwd_of_process(pid: int) -> str:
|
||||
import subprocess
|
||||
cp = subprocess.run(['pwdx', str(pid)], capture_output=True)
|
||||
if cp.returncode != 0:
|
||||
raise ValueError(f'Failed to find cwd of process with pid: {pid}')
|
||||
ans = cp.stdout.decode('utf-8', 'replace').split()[1]
|
||||
return os.path.realpath(ans)
|
||||
else:
|
||||
def cwd_of_process(pid: int) -> str:
|
||||
ans = f'/proc/{pid}/cwd'
|
||||
return os.path.realpath(ans)
|
||||
|
||||
@ -26,6 +26,7 @@ version: Version = Version(0, 25, 0)
|
||||
str_version: str = '.'.join(map(str, version))
|
||||
_plat = sys.platform.lower()
|
||||
is_macos: bool = 'darwin' in _plat
|
||||
is_freebsd: bool = 'freebsd' in _plat
|
||||
is_running_from_develop: bool = False
|
||||
if getattr(sys, 'frozen', False):
|
||||
extensions_dir: str = getattr(sys, 'kitty_extensions_dir')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user