Solve #2 Add copy reference alias of a copy relative file path with line by clempat · Pull Request #3 · NickHatBoecker/CopyFilepathWithLineNumbers · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Context.sublime-commands
4 changes: 4 additions & 0 deletions Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
{
"caption": "Copy Filepath With Line Numbers",
"command": "copy_filepath_with_line_numbers"
},
{
"caption": "Copy Reference",
"command": "copy_reference"
}
]
45 changes: 32 additions & 13 deletions CopyFilepathWithLineNumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,40 @@
import shutil
import os.path

class CopyFilepathWithLineNumbersCommand(sublime_plugin.TextCommand):
def run(self, edit):
fileName = self.view.file_name()
def getLines(self):
(rowStart, colStart) = self.view.rowcol(self.view.sel()[0].begin())
(rowEnd, colEnd) = self.view.rowcol(self.view.sel()[0].end())

if fileName == None:
sublime.error_message("You have to save the file first!")
return
lines = (str) (rowStart + 1)

(rowStart, colStart) = self.view.rowcol(self.view.sel()[0].begin())
(rowEnd, colEnd) = self.view.rowcol(self.view.sel()[0].end())
if rowStart != rowEnd:
#multiple selection
lines += "-" + (str) (rowEnd + 1)

result = fileName + ":" + (str)(rowStart + 1)
return lines

if rowStart != rowEnd:
# multiple selection
result += "-" + (str)(rowEnd + 1)

sublime.set_clipboard(result)
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)
9 changes: 8 additions & 1 deletion readme.md