Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cwd for non-vte shells #123

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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