Files
kitty-nautilus/kitty-nautilus.py
Jonas Kattendick b59136286e fix: use -d option to set cwd
Older kitty versions don't have the `--working-directory` alias.
2022-09-26 15:37:59 +02:00

46 lines
1.5 KiB
Python

import locale
import os
import subprocess
from gi.repository import Nautilus, GObject
TRANSLATIONS = {
"de": ("In Kitty öffnen", "Den Ordner in Kitty öffnen"),
"en": ("Open in Kitty", "Opens the current folder in Kitty"),
}
class KittyNautilusExtension(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
# Derive lang from the system locale
default_locale = locale.getdefaultlocale()[0].split("_")[0]
lang = default_locale.split("_")[0]
# Define a save fallback, if translation for the lang does not exist
if lang not in TRANSLATIONS:
lang = "en"
self.intl = TRANSLATIONS[lang]
def launch_kitty(self, menu: Nautilus.MenuItem, path):
subprocess.Popen(["kitty", "-d", path], shell=False)
def make_item(self, name, path) -> Nautilus.MenuItem:
item = Nautilus.MenuItem(
name=name,
label=self.intl[0],
tip=self.intl[1],
icon="terminal",
)
item.connect("activate", self.launch_kitty, path)
return item
def get_file_items(self, _window, files) -> [Nautilus.MenuItem]:
if len(files) == 1:
path = files[0].get_location().get_path()
if os.path.isdir(path):
return [self.make_item("NautilusFileOpenKitty", path)]
def get_background_items(self, _window, file) -> [Nautilus.MenuItem]:
path = file.get_location().get_path()
return [self.make_item("NautilusBackgroundOpenKitty", path)]