Skip to content

Commit

Permalink
Merge pull request #123 from mattrose/pwdfix
Browse files Browse the repository at this point in the history
fix cwd for non-vte shells
  • Loading branch information
mattrose authored Jun 10, 2020
2 parents 86f9033 + cdc4567 commit f70737c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
28 changes: 8 additions & 20 deletions terminatorlib/cwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,21 @@
# GPL v2 only
"""cwd.py - function necessary to get the cwd for a given pid on various OSes
>>> cwd = get_default_cwd()
>>> cwd.__class__.__name__
'str'
>>> func = get_pid_cwd()
>>> cwd = get_pid_cwd(None)
>>> cwd.__class__.__name__
'str'
"""

import platform
import os
import pwd
import psutil
from .util import dbg, err

def get_default_cwd():
"""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)
from .util import dbg

def get_pid_cwd():
def get_pid_cwd(pid = None):
"""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:
7 changes: 4 additions & 3 deletions terminatorlib/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .util import dbg, err, spawn_new_terminator, make_uuid, manual_lookup, display_manager
from . import util
from .config import Config
from .cwd import get_default_cwd
from .cwd import get_pid_cwd
from .factory import Factory
from .terminator import Terminator
from .titlebar import Titlebar
Expand Down Expand Up @@ -128,7 +128,7 @@ def __init__(self):

self.config = Config()

self.cwd = get_default_cwd()
self.cwd = get_pid_cwd()
self.origcwd = self.terminator.origcwd
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

Expand Down Expand Up @@ -223,7 +223,8 @@ def get_cwd(self):
return(GLib.filename_from_uri(vte_cwd)[0])
else:
# 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):
"""Close ourselves"""
Expand Down
4 changes: 0 additions & 4 deletions terminatorlib/terminator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from .keybindings import Keybindings
from .util import dbg, err, enumerate_descendants
from .factory import Factory
from .cwd import get_pid_cwd
from .version import APP_NAME, APP_VERSION

try:
Expand Down Expand Up @@ -54,7 +53,6 @@ class Terminator(Borg):
origcwd = None
dbus_path = None
dbus_name = None
pid_cwd = None
gnome_client = None
debug_address = None
ibus_running = None
Expand Down Expand Up @@ -98,8 +96,6 @@ def prepare_attributes(self):
self.style_providers = []
if not self.doing_layout:
self.doing_layout = False
if not self.pid_cwd:
self.pid_cwd = get_pid_cwd
if self.gnome_client is None:
self.attempt_gnome_client()
self.connect_signals()
Expand Down

0 comments on commit f70737c

Please sign in to comment.