From 09d6a1ee2ee8c79f0690d271935d201cf4694ac9 Mon Sep 17 00:00:00 2001 From: Sebastian Wiesner Date: Mon, 29 Dec 2025 22:25:33 +0100 Subject: [PATCH] Lift functions out of class Neither of these used self. --- dist/linux/ghostty_nautilus.py | 48 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/dist/linux/ghostty_nautilus.py b/dist/linux/ghostty_nautilus.py index 965e8107e..e993d0aaa 100644 --- a/dist/linux/ghostty_nautilus.py +++ b/dist/linux/ghostty_nautilus.py @@ -20,37 +20,39 @@ from gi.repository import Nautilus, GObject, Gio -class OpenInGhosttyAction(GObject.GObject, Nautilus.MenuProvider): - def _menu_item_activated(self, _menu, paths): - for path in paths: - cmd = ['ghostty', f'--working-directory={path}', '--gtk-single-instance=false'] - Gio.Subprocess.new(cmd, Gio.SubprocessFlags.NONE) +def open_in_ghostty_activated(_menu, paths): + for path in paths: + cmd = ['ghostty', f'--working-directory={path}', '--gtk-single-instance=false'] + Gio.Subprocess.new(cmd, Gio.SubprocessFlags.NONE) + +def get_paths_to_open(files): + paths = [] + for file in files: + location = file.get_location() if file.is_directory() else file.get_parent_location() + path = location.get_path() + if path and path not in paths: + paths.append(path) + if 10 < len(paths): + # Let's not open anything if the user selected a lot of directories, + # to avoid accidentally spamming their desktop with dozends of + # new windows or tabs. Ten is a totally arbitrary limit :) + return [] + else: + return paths + + +class OpenInGhosttyAction(GObject.GObject, Nautilus.MenuProvider): def _make_item(self, name, paths): item = Nautilus.MenuItem(name=name, label='Open in Ghostty', icon='com.mitchellh.ghostty') - item.connect('activate', self._menu_item_activated, paths) + item.connect('activate', open_in_ghostty_activated, paths) return item - def _paths_to_open(self, files): - paths = [] - for file in files: - location = file.get_location() if file.is_directory() else file.get_parent_location() - path = location.get_path() - if path and path not in paths: - paths.append(path) - if 10 < len(paths): - # Let's not open anything if the user selected a lot of directories, - # to avoid accidentally spamming their desktop with dozends of - # new windows or tabs. Ten is a totally arbitrary limit :) - return [] - else: - return paths - def get_file_items(self, *args): # Nautilus 3.0 API passes args (window, files), 4.0 API just passes files files = args[0] if len(args) == 1 else args[1] - paths = self._paths_to_open(files) + paths = get_paths_to_open(files) if paths: return [self._make_item(name='GhosttyNautilus::open_in_ghostty', paths=paths)] else: @@ -59,7 +61,7 @@ class OpenInGhosttyAction(GObject.GObject, Nautilus.MenuProvider): def get_background_items(self, *args): # Nautilus 3.0 API passes args (window, file), 4.0 API just passes file file = args[0] if len(args) == 1 else args[1] - paths = self._paths_to_open([file]) + paths = get_paths_to_open([file]) if paths: return [self._make_item(name='GhosttyNautilus::open_folder_in_ghostty', paths=paths)] else: