/usr/share/nautilus-python/extensions/open-tilix.py is in tilix-common 1.7.7-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | # -*- coding: UTF-8 -*-
# This example is contributed by Martin Enlund
# Example modified for Tilix
# Shortcuts Provider was inspired by captain nemo extension
from gettext import gettext, textdomain
from subprocess import PIPE, call
try:
from urllib import unquote
from urlparse import urlparse
except ImportError:
from urllib.parse import unquote, urlparse
from gi import require_version
require_version('Gtk', '3.0')
require_version('Nautilus', '3.0')
from gi.repository import Gio, GObject, Gtk, Nautilus
TERMINAL = "tilix"
TILIX_KEYBINDINGS = "com.gexperts.Tilix.Keybindings"
GSETTINGS_OPEN_TERMINAL = "nautilus-open"
REMOTE_URI_SCHEME = ['ftp', 'sftp']
textdomain("tilix")
_ = gettext
def open_terminal_in_file(filename):
if filename:
call('{0} -w "{1}" &'.format(TERMINAL, filename), shell=True)
else:
call("{0} &".format(TERMINAL), shell=True)
class OpenTilixShortcutProvider(GObject.GObject,
Nautilus.LocationWidgetProvider):
def __init__(self):
source = Gio.SettingsSchemaSource.get_default()
if source.lookup(TILIX_KEYBINDINGS, True):
self._gsettings = Gio.Settings.new(TILIX_KEYBINDINGS)
self._gsettings.connect("changed", self._bind_shortcut)
self._create_accel_group()
self._window = None
self._uri = None
def _create_accel_group(self):
self._accel_group = Gtk.AccelGroup()
shortcut = self._gsettings.get_string(GSETTINGS_OPEN_TERMINAL)
key, mod = Gtk.accelerator_parse(shortcut)
self._accel_group.connect(key, mod, Gtk.AccelFlags.VISIBLE,
self._open_terminal)
def _bind_shortcut(self, gsettings, key):
if key == GSETTINGS_OPEN_TERMINAL:
self._accel_group.disconnect(self._open_terminal)
self._create_accel_group()
def _open_terminal(self, *args):
filename = unquote(self._uri[7:])
open_terminal_in_file(filename)
def get_widget(self, uri, window):
self._uri = uri
if self._window:
self._window.remove_accel_group(self._accel_group)
if self._gsettings:
window.add_accel_group(self._accel_group)
self._window = window
return None
class OpenTilixExtension(GObject.GObject, Nautilus.MenuProvider):
def _open_terminal(self, file_):
if file_.get_uri_scheme() in REMOTE_URI_SCHEME:
result = urlparse(file_.get_uri())
if result.username:
value = 'ssh -t {0}@{1}'.format(result.username,
result.hostname)
else:
value = 'ssh -t {0}'.format(result.hostname)
if result.port:
value = "{0} -p {1}".format(value, result.port)
if file_.is_directory():
value = '{0} cd "{1}" ; $SHELL'.format(value, result.path)
call('{0} -e "{1}" &'.format(TERMINAL, value), shell=True)
else:
filename = Gio.File.new_for_uri(file_.get_uri()).get_path()
open_terminal_in_file(filename)
def _menu_activate_cb(self, menu, file_):
self._open_terminal(file_)
def _menu_background_activate_cb(self, menu, file_):
self._open_terminal(file_)
def get_file_items(self, window, files):
if len(files) != 1:
return
items = []
file_ = files[0]
print("Handling file: ", file_.get_uri())
print("file scheme: ", file_.get_uri_scheme())
if file_.is_directory():
if file_.get_uri_scheme() in REMOTE_URI_SCHEME:
uri = file_.get_uri().decode('utf-8')
item = Nautilus.MenuItem(name='NautilusPython::open_remote_item',
label=_(u'Open Remote Tilix'),
tip=_(u'Open Remote Tilix In {}').format(uri))
item.connect('activate', self._menu_activate_cb, file_)
items.append(item)
filename = file_.get_name().decode('utf-8')
item = Nautilus.MenuItem(name='NautilusPython::open_file_item',
label=_(u'Open In Tilix'),
tip=_(u'Open Tilix In {}').format(filename))
item.connect('activate', self._menu_activate_cb, file_)
items.append(item)
return items
def get_background_items(self, window, file_):
items = []
if file_.get_uri_scheme() in REMOTE_URI_SCHEME:
item = Nautilus.MenuItem(name='NautilusPython::open_bg_remote_item',
label=_(u'Open Remote Tilix Here'),
tip=_(u'Open Remote Tilix In This Directory'))
item.connect('activate', self._menu_activate_cb, file_)
items.append(item)
item = Nautilus.MenuItem(name='NautilusPython::open_bg_file_item',
label=_(u'Open Tilix Here'),
tip=_(u'Open Tilix In This Directory'))
item.connect('activate', self._menu_background_activate_cb, file_)
items.append(item)
return items
|