Last active
July 28, 2020 14:13
-
-
Save goncalossilva/c7cc77d95da3f24b197dda4651422d38 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# | |
# Open With Nautilus Extension. | |
# | |
# Install python-nautilus and put this in ~/.local/share/nautilus-python/extensions/. | |
from gi import require_version | |
require_version("Gtk", "3.0") | |
require_version("Nautilus", "3.0") | |
from gi.repository import Nautilus, GObject | |
from subprocess import call | |
import os | |
# Change this if needed. | |
EXEC = "gvim" | |
NAME = "GVim" | |
class OpenWithExtension(GObject.GObject, Nautilus.MenuProvider): | |
def launch(self, menu, files): | |
safepaths = "" | |
for file in files: | |
filepath = file.get_location().get_path() | |
safepaths += '"' + filepath + '" ' | |
call(EXEC + " " + safepaths, shell=True) | |
def get_file_items(self, _window, files): | |
item = Nautilus.MenuItem( | |
name=NAME + "Open", | |
label="Open With " + NAME, | |
tip="Opens the selected files with " + NAME, | |
) | |
item.connect("activate", self.launch, files) | |
return [item] | |
def get_background_items(self, _window, file_): | |
item = Nautilus.MenuItem( | |
name=NAME + "OpenBackground", | |
label="Open " + NAME + " Here", | |
tip="Opens " + NAME + " in the current directory", | |
) | |
item.connect("activate", self.launch, [file_]) | |
return [item] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment