-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinder.py
41 lines (30 loc) · 1.02 KB
/
finder.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
import sublime_plugin
import subprocess
import os
class FinderCommand:
def get_path(self, path):
if path:
return path
if self.window.active_view():
file = self.window.active_view().file_name()
if file:
return file
if self.window.folders():
return self.window.folders()[0]
pd = self.window.project_data()
if pd and "folders" in pd and len(pd["folders"]) > 0:
project_path = pd["folders"][0].get("path")
if project_path:
return project_path
return '.'
class OpenFinderCommand(sublime_plugin.WindowCommand, FinderCommand):
def run(self, path=""):
path = self.get_path(path)
if os.path.isfile(path):
call = ['open', '-R', path]
else:
call = ['open', path]
p = subprocess.Popen(call, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if stderr:
print(stderr)