-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnautilus-sublime.py
64 lines (49 loc) · 1.79 KB
/
nautilus-sublime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# SublimeText Nautilus Extension
#
# Place me in ~/.local/share/nautilus-python/extensions/,
# ensure you have python-nautilus package, restrart Nautilus, and enjoy :)
#
# Based on cra0zy's script for VSCode.
# Modified for Sublime by Przemas.
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
# path to SublimeText
SUBL = "subl"
# what name do you want to see in the context menu?
SUBLNAME = "SublimeText"
# always create new window?
NEWWINDOW = True
class SublimeTextExtension(GObject.GObject, Nautilus.MenuProvider):
def launch_sublime(self, menu, files):
safepaths = ""
args = ""
for file in files:
filepath = file.get_location().get_path()
safepaths += '"' + filepath + '" '
# If one of the files we are trying to open is a folder
# create a new instance of Sublime
if os.path.isdir(filepath) and os.path.exists(filepath):
args = "-wn "
if NEWWINDOW:
args = "-wn "
call(SUBL + " " + args + safepaths + "&", shell=True)
def get_file_items(self, window, files):
item = Nautilus.MenuItem(
name="SublimeTextOpen",
label="Open In " + SUBLNAME,
tip="Opens the selected files with SublimeText",
)
item.connect("activate", self.launch_sublime, files)
return [item]
def get_background_items(self, window, file_):
item = Nautilus.MenuItem(
name="SublimeOpenBackground",
label="Open in " + SUBLNAME,
tip="Opens SublimeText in the current directory",
)
item.connect("activate", self.launch_sublime, [file_])
return [item]