forked from rrg/ListOpenFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listopenfiles.py
32 lines (27 loc) · 1.02 KB
/
listopenfiles.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
import sublime,sublime_plugin,os
from os.path import relpath
class ListOpenFilesCommand(sublime_plugin.TextCommand):
def run(self, edit):
window = sublime.active_window()
views = window.views()
fileNames = ''
for view in views:
if view and view.file_name():
# fileNames += os.path.basename(view.file_name())+'\n'
fileNames += self.getRelativePathOfFile(view.file_name())+'\n'
window.new_file().insert(edit, 0, "List of open files:\n\n"+fileNames)
def getRelativePathOfFile(self, filename):
if len(filename) > 0:
try :
thePath = (
min(
(
relpath(filename, folder).replace("\\", "/")
for folder in sublime.active_window().folders()
),
key=len,
)
)
except :
thePath = filename
return thePath