Skip to content

Instantly share code, notes, and snippets.

@aunetx
Created May 13, 2021 22:09
Show Gist options
  • Save aunetx/5427b8afabf44ae14cfb1fef4914de85 to your computer and use it in GitHub Desktop.
Save aunetx/5427b8afabf44ae14cfb1fef4914de85 to your computer and use it in GitHub Desktop.
A nautilus extension to open Mt in the current directory, instead of gnome-terminal.
# placed in /usr/share/nautilus-python/extensions/open-mt.py
# french version
# translate and enjoy
import subprocess
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
import gi
gi.require_version('GConf', '2.0')
from gi.repository import Nautilus, GObject, GConf
class OpenTerminalExtension(Nautilus.MenuProvider, GObject.GObject):
def __init__(self):
self.client = GConf.Client.get_default()
def _open_terminal(self, file):
filename = unquote(file.get_uri()[7:])
subprocess.Popen(["Mt", "-w", 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
file = files[0]
if not file.is_directory() or file.get_uri_scheme() != 'file':
return
item = Nautilus.MenuItem(name='Mt::open_terminal_for_dir',
# TIPs: translate sentences here...
label='Ouvrir dans un terminal' , # 'Open in a terminal'
tip='Ouvrir un terminal dans %s' % file.get_name()) # 'Open a terminal in %s'
item.connect('activate', self.menu_activate_cb, file)
return item,
def get_background_items(self, window, file):
item = Nautilus.MenuItem(name='Mt::open_terminal_current_dir',
# TIPs: ...and here!
label='Ouvrir un terminal' , # 'Open a terminal'
tip='Ouvrir un terminal dans %s' % file.get_name()) # 'Open a terminal in %s'
item.connect('activate', self.menu_background_activate_cb, file)
return item,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment