clone of my dotfiles.ssp.sh
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add context menu to file explorer

sspaeti d948c93b 7828213e

+117
+81
nautilus/.local/share/nautilus-python/extensions/custom_actions.py
··· 1 + from gi.repository import Nautilus, GObject 2 + import subprocess 3 + import os 4 + 5 + 6 + class CustomActions(GObject.GObject, Nautilus.MenuProvider): 7 + def _paths_to_open(self, files): 8 + paths = [] 9 + for file in files: 10 + location = file.get_location() if file.is_directory() else file.get_parent_location() 11 + path = location.get_path() 12 + if path and path not in paths: 13 + paths.append(path) 14 + return paths if len(paths) <= 10 else [] 15 + 16 + # --- Open in Tmux --- 17 + def _open_in_tmux(self, _menu, paths): 18 + for path in paths: 19 + result = subprocess.run(['tmux', 'list-sessions'], capture_output=True) 20 + if result.returncode == 0: 21 + subprocess.Popen(['tmux', 'new-window', '-c', path]) 22 + else: 23 + subprocess.Popen(['foot', '--working-directory', path, '-e', 'tmux', 'new-session']) 24 + 25 + # --- Open in Terminal --- 26 + def _open_in_terminal(self, _menu, paths): 27 + for path in paths: 28 + subprocess.Popen(['foot', '--working-directory', path, '-e', 'zsh']) 29 + 30 + # --- Copy File Name --- 31 + def _copy_file_name(self, _menu, files): 32 + names = [os.path.basename(f.get_location().get_path()) for f in files if f.get_location().get_path()] 33 + if names: 34 + subprocess.Popen(['wl-copy', '\n'.join(names)]) 35 + 36 + # --- Copy File Path --- 37 + def _copy_file_path(self, _menu, files): 38 + paths = [f.get_location().get_path() for f in files if f.get_location().get_path()] 39 + if paths: 40 + subprocess.Popen(['wl-copy', '\n'.join(paths)]) 41 + 42 + def get_file_items(self, *args): 43 + files = args[0] if len(args) == 1 else args[1] 44 + if not files: 45 + return [] 46 + 47 + items = [] 48 + paths = self._paths_to_open(files) 49 + 50 + if paths: 51 + tmux = Nautilus.MenuItem(name='Custom::open_tmux', label='Open in Tmux', icon='utilities-terminal') 52 + tmux.connect('activate', self._open_in_tmux, paths) 53 + items.append(tmux) 54 + 55 + terminal = Nautilus.MenuItem(name='Custom::open_terminal', label='Open in Terminal', icon='utilities-terminal') 56 + terminal.connect('activate', self._open_in_terminal, paths) 57 + items.append(terminal) 58 + 59 + name_item = Nautilus.MenuItem(name='Custom::copy_name', label='Copy File Name', icon='edit-copy') 60 + name_item.connect('activate', self._copy_file_name, files) 61 + items.append(name_item) 62 + 63 + path_item = Nautilus.MenuItem(name='Custom::copy_path', label='Copy File Path', icon='edit-copy') 64 + path_item.connect('activate', self._copy_file_path, files) 65 + items.append(path_item) 66 + 67 + return items 68 + 69 + def get_background_items(self, *args): 70 + file = args[0] if len(args) == 1 else args[1] 71 + paths = self._paths_to_open([file]) 72 + if not paths: 73 + return [] 74 + 75 + tmux = Nautilus.MenuItem(name='Custom::open_tmux_bg', label='Open in Tmux', icon='utilities-terminal') 76 + tmux.connect('activate', self._open_in_tmux, paths) 77 + 78 + terminal = Nautilus.MenuItem(name='Custom::open_terminal_bg', label='Open in Terminal', icon='utilities-terminal') 79 + terminal.connect('activate', self._open_in_terminal, paths) 80 + 81 + return [tmux, terminal]
+36
nautilus/install.sh
··· 1 + #!/bin/bash 2 + # Install nautilus context menu items: 3 + # - Scripts (under Scripts submenu): ExifTool Info 4 + # - Python extensions (root context menu): Open in Terminal, Copy File Name, Copy File Path 5 + 6 + DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)" 7 + 8 + # Install nautilus scripts (appear under Scripts submenu) 9 + SCRIPTS_DIR="$HOME/.local/share/nautilus/scripts" 10 + SCRIPTS_SOURCE="$DOTFILES_DIR/.local/share/nautilus/scripts" 11 + mkdir -p "$SCRIPTS_DIR" 12 + 13 + for script in "$SCRIPTS_SOURCE"/*; do 14 + name="$(basename "$script")" 15 + ln -sf "$script" "$SCRIPTS_DIR/$name" 16 + done 17 + 18 + # Install nautilus-python extensions (appear at root context menu level) 19 + EXT_DIR="$HOME/.local/share/nautilus-python/extensions" 20 + EXT_SOURCE="$DOTFILES_DIR/.local/share/nautilus-python/extensions" 21 + mkdir -p "$EXT_DIR" 22 + 23 + for ext in "$EXT_SOURCE"/*.py; do 24 + name="$(basename "$ext")" 25 + ln -sf "$ext" "$EXT_DIR/$name" 26 + done 27 + 28 + # Disable Ghostty's built-in extension (replaced by Open in Terminal) 29 + GHOSTTY_EXT="/usr/share/nautilus-python/extensions/ghostty.py" 30 + if [ -f "$GHOSTTY_EXT" ] && [ ! -f "${GHOSTTY_EXT}.disabled" ]; then 31 + echo "Disabling Ghostty nautilus extension (replaced by Open in Terminal)..." 32 + sudo mv "$GHOSTTY_EXT" "${GHOSTTY_EXT}.disabled" 33 + fi 34 + 35 + echo "Installed nautilus scripts and extensions." 36 + echo "Restart nautilus (nautilus -q) for changes to take effect."