fix cwd for non-vte shells

This commit is contained in:
Matt Rose 2020-06-10 12:10:09 -04:00
parent 9d5c2a6bb3
commit cdc456740b
3 changed files with 12 additions and 27 deletions

View File

@ -2,33 +2,21 @@
# GPL v2 only # GPL v2 only
"""cwd.py - function necessary to get the cwd for a given pid on various OSes """cwd.py - function necessary to get the cwd for a given pid on various OSes
>>> cwd = get_default_cwd()
>>> cwd.__class__.__name__ >>> cwd = get_pid_cwd(None)
'str'
>>> func = get_pid_cwd()
>>> cwd.__class__.__name__ >>> cwd.__class__.__name__
'str' 'str'
""" """
import platform
import os
import pwd
import psutil import psutil
from .util import dbg, err from .util import dbg
def get_default_cwd(): def get_pid_cwd(pid = None):
"""Determine a reasonable default cwd"""
try:
cwd = os.getcwd()
except (FileNotFoundError,OSError):
err("unable to set current working directory, does not exist")
cwd = '/'
return(cwd)
def get_pid_cwd():
"""Determine the cwd of the current process""" """Determine the cwd of the current process"""
return psutil.Process().as_dict()['cwd'] psinfo = psutil.Process(pid).as_dict()
dbg('psinfo: %s %s' % (psinfo['cwd'],psinfo['pid']))
# return func
return psinfo['cwd']
# vim: set expandtab ts=4 sw=4: # vim: set expandtab ts=4 sw=4:

View File

@ -18,7 +18,7 @@ except ImportError:
from .util import dbg, err, spawn_new_terminator, make_uuid, manual_lookup, display_manager from .util import dbg, err, spawn_new_terminator, make_uuid, manual_lookup, display_manager
from . import util from . import util
from .config import Config from .config import Config
from .cwd import get_default_cwd from .cwd import get_pid_cwd
from .factory import Factory from .factory import Factory
from .terminator import Terminator from .terminator import Terminator
from .titlebar import Titlebar from .titlebar import Titlebar
@ -128,7 +128,7 @@ class Terminal(Gtk.VBox):
self.config = Config() self.config = Config()
self.cwd = get_default_cwd() self.cwd = get_pid_cwd()
self.origcwd = self.terminator.origcwd self.origcwd = self.terminator.origcwd
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
@ -223,7 +223,8 @@ class Terminal(Gtk.VBox):
return(GLib.filename_from_uri(vte_cwd)[0]) return(GLib.filename_from_uri(vte_cwd)[0])
else: else:
# Fall back to old gtk2 method # Fall back to old gtk2 method
return(self.terminator.pid_cwd()) dbg('calling get_pid_cwd')
return(get_pid_cwd(self.pid))
def close(self): def close(self):
"""Close ourselves""" """Close ourselves"""

View File

@ -15,7 +15,6 @@ from .config import Config
from .keybindings import Keybindings from .keybindings import Keybindings
from .util import dbg, err, enumerate_descendants from .util import dbg, err, enumerate_descendants
from .factory import Factory from .factory import Factory
from .cwd import get_pid_cwd
from .version import APP_NAME, APP_VERSION from .version import APP_NAME, APP_VERSION
try: try:
@ -54,7 +53,6 @@ class Terminator(Borg):
origcwd = None origcwd = None
dbus_path = None dbus_path = None
dbus_name = None dbus_name = None
pid_cwd = None
gnome_client = None gnome_client = None
debug_address = None debug_address = None
ibus_running = None ibus_running = None
@ -98,8 +96,6 @@ class Terminator(Borg):
self.style_providers = [] self.style_providers = []
if not self.doing_layout: if not self.doing_layout:
self.doing_layout = False self.doing_layout = False
if not self.pid_cwd:
self.pid_cwd = get_pid_cwd
if self.gnome_client is None: if self.gnome_client is None:
self.attempt_gnome_client() self.attempt_gnome_client()
self.connect_signals() self.connect_signals()