diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap
index 14d0884..f39c2ec 100644
--- a/Default (Linux).sublime-keymap
+++ b/Default (Linux).sublime-keymap
@@ -6,5 +6,9 @@
{
"keys": ["alt+s"],
"command": "sourcegraph_search"
+ },
+ {
+ "keys": ["alt+c"]
+ "command": ["sourcegraph_copy"]
}
]
diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap
index c4c8036..dad445d 100644
--- a/Default (OSX).sublime-keymap
+++ b/Default (OSX).sublime-keymap
@@ -6,5 +6,9 @@
{
"keys": ["option+s"],
"command": "sourcegraph_search"
+ },
+ {
+ "keys": ["option+c"]
+ "command": ["sourcegraph_copy"]
}
]
diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap
index 14d0884..f39c2ec 100644
--- a/Default (Windows).sublime-keymap
+++ b/Default (Windows).sublime-keymap
@@ -6,5 +6,9 @@
{
"keys": ["alt+s"],
"command": "sourcegraph_search"
+ },
+ {
+ "keys": ["alt+c"]
+ "command": ["sourcegraph_copy"]
}
]
diff --git a/README.md b/README.md
index 264d7c5..72a869d 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Keyboard Shortcuts:
|---------------------------------|---------------------|------------------|
| Open file in Sourcegraph | Option+A | Alt+A |
| Search selection in Sourcegraph | Option+S | Alt+S |
-
+| Copy link from Sourcegraph | Option+C | Alt+C |
## Settings
@@ -70,6 +70,9 @@ To develop the plugin:
## Version History
+- v1.0.8 - Add copy functionality.
+ - Create shortcut which copies a the file from a given Sourcegraph link.
+
- v1.0.7 - Correctly open the default browser on Mac OS.
- Added a workaround for a Mac OS bug that causes Python to incorrectly open the second (non-default) browser. https://bugs.python.org/issue30392
diff --git a/Sourcegraph.sublime-commands b/Sourcegraph.sublime-commands
index 1a96d82..5d2a8b5 100644
--- a/Sourcegraph.sublime-commands
+++ b/Sourcegraph.sublime-commands
@@ -35,4 +35,8 @@
"caption": "Sourcegraph: Search",
"command": "sourcegraph_search"
}
+ {
+ "caption": "Sourcegraph: Copy",
+ "command": "sourcegraph_copy"
+ }
]
diff --git a/messages.json b/messages.json
index c0c4018..ac0bc8e 100644
--- a/messages.json
+++ b/messages.json
@@ -7,5 +7,6 @@
"1.0.4": "messages/welcome.txt",
"1.0.5": "messages/welcome.txt",
"1.0.6": "messages/welcome.txt",
- "1.0.7": "messages/welcome.txt"
+ "1.0.7": "messages/welcome.txt",
+ "1.0.8": "messages/welcome.txt"
}
diff --git a/messages/welcome.txt b/messages/welcome.txt
index c40c103..ec45901 100644
--- a/messages/welcome.txt
+++ b/messages/welcome.txt
@@ -18,10 +18,14 @@ Usage
|---------------------------------|------------|-----------------|
| Open file in Sourcegraph | `Option+A` | `Alt+A` |
| Search selection in Sourcegraph | `Option+S` | `Alt+S` |
+ | Copy link from Sourcegraph | `Option+C` | `Alt+C` |
Version History
===============
+ - v1.0.8 - Add copy functionality.
+ - Create shortcut which copies a the file from a given Sourcegraph link.
+
v1.0.7 - Correctly open the default browser on Mac OS.
- Added a workaround for a Mac OS bug that causes Python to incorrectly open the second (non-default) browser. https://bugs.python.org/issue30392
diff --git a/sourcegraph.py b/sourcegraph.py
index 516d9a0..4fecb86 100644
--- a/sourcegraph.py
+++ b/sourcegraph.py
@@ -14,7 +14,7 @@
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
-VERSION = 'v1.0.7'
+VERSION = 'v1.0.8'
FILENAME_SETTINGS = 'Sourcegraph.sublime-settings'
# gitRemotes returns the names of all git remotes, e.g. ['origin', 'foobar']
@@ -126,6 +126,42 @@ def run(self, edit):
})
webbrowserOpen(url)
+class SourcegraphCopyCommand(sublime_plugin.TextCommand):
+ def run(self, edit):
+ remoteURL, branch, fileRel = repoInfo(self.view.file_name())
+ if remoteURL == "":
+ return
+
+ # For now, we assume the first selection is the most interesting one.
+ (row,col) = self.view.rowcol(self.view.sel()[0].begin())
+ (row2,col2) = self.view.rowcol(self.view.sel()[0].end())
+
+ # Open in browser
+ settings = sublime.load_settings(FILENAME_SETTINGS)
+ url = sourcegraphURL(settings)+'-/editor?' + urlencode({
+ 'remote_url': remoteURL,
+ 'branch': branch,
+ 'file': fileRel,
+ 'editor': 'Sublime',
+ 'version': VERSION,
+
+ 'start_row': row,
+ 'start_col': col,
+ 'end_row': row2,
+ 'end_col': col2,
+ })
+ subprocess.run("pbcopy", universal_newlines=True, input=url)
+
+class SourcegraphEditCommand(sublime_plugin.WindowCommand):
+ def run(self, edit):
+ url = self.window.show_input_panel('Sourcegraph Link: ', '', self.copy, None, None)
+ if self.copy == '':
+ return 'No link provided.'
+
+
+
+
+
def webbrowserOpen(url):
if sys.platform == 'darwin':
# HACK: There exists a bug in a bad release of MacOS that breaks