Revert to gtk2 of cwd detection, as method from Egmonts gtk3 port only returned None for me
This commit is contained in:
parent
56c9875395
commit
7e89aa14b3
@ -6,6 +6,9 @@
|
||||
>>> cwd = get_default_cwd()
|
||||
>>> cwd.__class__.__name__
|
||||
'str'
|
||||
>>> func = get_pid_cwd()
|
||||
>>> func.__class__.__name__
|
||||
'function'
|
||||
|
||||
"""
|
||||
|
||||
@ -25,4 +28,47 @@ def get_default_cwd():
|
||||
|
||||
return(cwd)
|
||||
|
||||
def get_pid_cwd():
|
||||
"""Determine an appropriate cwd function for the OS we are running on"""
|
||||
|
||||
func = lambda pid: None
|
||||
system = platform.system()
|
||||
|
||||
if system == 'Linux':
|
||||
dbg('Using Linux get_pid_cwd')
|
||||
func = linux_get_pid_cwd
|
||||
elif system == 'FreeBSD':
|
||||
try:
|
||||
import freebsd
|
||||
func = freebsd.get_process_cwd
|
||||
dbg('Using FreeBSD get_pid_cwd')
|
||||
except (OSError, NotImplementedError, ImportError):
|
||||
dbg('FreeBSD version too old for get_pid_cwd')
|
||||
elif system == 'SunOS':
|
||||
dbg('Using SunOS get_pid_cwd')
|
||||
func = sunos_get_pid_cwd
|
||||
else:
|
||||
dbg('Unable to determine a get_pid_cwd for OS: %s' % system)
|
||||
|
||||
return(func)
|
||||
|
||||
def proc_get_pid_cwd(pid, path):
|
||||
"""Extract the cwd of a PID from proc, given the PID and the /proc path to
|
||||
insert it into, e.g. /proc/%s/cwd"""
|
||||
try:
|
||||
cwd = os.path.realpath(path % pid)
|
||||
except Exception, ex:
|
||||
err('Unable to get cwd for PID %s: %s' % (pid, ex))
|
||||
cwd = '/'
|
||||
|
||||
return(cwd)
|
||||
|
||||
def linux_get_pid_cwd(pid):
|
||||
"""Determine the cwd for a given PID on Linux kernels"""
|
||||
return(proc_get_pid_cwd(pid, '/proc/%s/cwd'))
|
||||
|
||||
def sunos_get_pid_cwd(pid):
|
||||
"""Determine the cwd for a given PID on SunOS kernels"""
|
||||
return(proc_get_pid_cwd(pid, '/proc/%s/path/cwd'))
|
||||
|
||||
# vim: set expandtab ts=4 sw=4:
|
||||
|
@ -190,7 +190,9 @@ class Terminal(Gtk.VBox):
|
||||
|
||||
def get_cwd(self):
|
||||
"""Return our cwd"""
|
||||
return(GLib.filename_from_uri(self.vte.get_current_directory_uri())[0])
|
||||
# Disabled and reverted to revert to old style cwd detection as only returns None.
|
||||
# return(GLib.filename_from_uri(self.vte.get_current_directory_uri())[0])
|
||||
return(self.terminator.pid_cwd(self.pid))
|
||||
|
||||
def close(self):
|
||||
"""Close ourselves"""
|
||||
@ -1563,10 +1565,10 @@ class Terminal(Gtk.VBox):
|
||||
self.emit('navigate', 'right')
|
||||
|
||||
def key_split_horiz(self):
|
||||
self.emit('split-horiz', self.get_cwd)
|
||||
self.emit('split-horiz', self.get_cwd())
|
||||
|
||||
def key_split_vert(self):
|
||||
self.emit('split-vert', self.get_cwd)
|
||||
self.emit('split-vert', self.get_cwd())
|
||||
|
||||
def key_rotate_cw(self):
|
||||
self.emit('rotate-cw')
|
||||
@ -1668,7 +1670,7 @@ class Terminal(Gtk.VBox):
|
||||
self.emit('ungroup-tab')
|
||||
|
||||
def key_new_window(self):
|
||||
self.terminator.new_window(self.get_cwd)
|
||||
self.terminator.new_window(self.get_cwd())
|
||||
|
||||
def key_new_terminator(self):
|
||||
spawn_new_terminator(self.origcwd, ['-u'])
|
||||
|
@ -12,6 +12,7 @@ from config import Config
|
||||
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
|
||||
|
||||
def eventkey2gdkevent(eventkey): # FIXME FOR GTK3: is there a simpler way of casting from specific EventKey to generic (union) GdkEvent?
|
||||
@ -43,6 +44,7 @@ class Terminator(Borg):
|
||||
origcwd = None
|
||||
dbus_path = None
|
||||
dbus_name = None
|
||||
pid_cwd = None
|
||||
gnome_client = None
|
||||
debug_address = None
|
||||
|
||||
@ -78,6 +80,8 @@ class Terminator(Borg):
|
||||
self.keybindings.configure(self.config['keybindings'])
|
||||
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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user