Skip to content

Instantly share code, notes, and snippets.

@aunetx
Last active May 29, 2022 17:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save aunetx/f93fd4c2287d4670173fda747cb72623 to your computer and use it in GitHub Desktop.
Save aunetx/f93fd4c2287d4670173fda747cb72623 to your computer and use it in GitHub Desktop.
A nautilus extension to open kitty in the current directory, instead of gnome-terminal.
# placed in ~/.local/share/nautilus-python/extensions/open-kitty.py
# you will need the package nautilus-python on fedora, or python-nautilus on ubuntu...
# french version
# translate and enjoy
import os
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:])
os.chdir(filename)
os.system('kitty --detach')
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='KittyTerminal::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='KittyTerminal::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,
@73
Copy link

73 commented Jan 6, 2021

Thanks. Works like a charm. 👍
However, I would like to suggest to place the script in: ~/.local/share/nautilus-python/extensions/open-kitty.py
On Ubuntu/Debian the package python3-nautilus is needed. Other distributions might refer to it as nautilus-python, like explained here.

@aunetx
Copy link
Author

aunetx commented May 27, 2021

Yeah, I actually placed it in user's local dir, but did not update it here :) thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment