-
Notifications
You must be signed in to change notification settings - Fork 4
/
CopyFilepathWithLineNumbers.py
42 lines (34 loc) · 1.35 KB
/
CopyFilepathWithLineNumbers.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
import sublime, sublime_plugin
import datetime
import shutil
import os.path
def getLines(self):
(rowStart, colStart) = self.view.rowcol(self.view.sel()[0].begin())
(rowEnd, colEnd) = self.view.rowcol(self.view.sel()[0].end())
lines = (str) (rowStart + 1)
if rowStart != rowEnd:
#multiple selection
lines += "-" + (str) (rowEnd + 1)
return lines
class CopyFilepathWithLineNumbersCommand(sublime_plugin.TextCommand):
def run(self, edit):
filename = self.view.file_name()
if len(filename) > 0:
sublime.set_clipboard(filename + ':' + getLines(self))
sublime.status_message("Copied path with line")
class CopyReferenceCommand(sublime_plugin.TextCommand):
def run(self, edit):
filename = self.view.file_name()
if len(filename) > 0:
# Copy shortest relpath for file compared to open folders
relativePath = min(
(
os.path.relpath(filename, folder)
for folder in sublime.active_window().folders()
),
key=len,
)
sublime.set_clipboard(relativePath + ':' + getLines(self))
sublime.status_message("Copied relative path with line")
def is_enabled(self):
return bool(self.view.file_name() and len(self.view.file_name()) > 0)