-
-
Save LorenzoMorelli/45a3b59f225201def6479ec758da1af5 to your computer and use it in GitHub Desktop.
A nautilus extension to open kitty in the current directory, instead of gnome-terminal.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
English version. | |
In Ubuntu 20.04 do this for installation: | |
1. Put this file on ~/.local/share/nautilus-python/extensions/open-kitty.py | |
2. Install python-nautilus: sudo apt install python-nautilus | |
3. Install gconf: sudo apt install gir1.2-gconf-2.0 | |
4. Restart nautilus: nautilus -q | |
Enjoy! | |
""" | |
import os | |
try: | |
from urllib import unquote | |
except ImportError: | |
from urllib.parse import unquote | |
import gi | |
gi.require_version('Nautilus', '3.0') | |
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', | |
label='Open Kitty Here' , # 'To translate, change language here and...' | |
tip='Open kitty in %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', | |
label='Open Kitty Here' , # '...change language here' | |
tip='Open kitty in %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