diff --git a/CHANGELOG.md b/CHANGELOG.md
index 72b6b21..44a5045 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.1.0 Add copy shortcut
+
+- Add copy link functionality.
+
## 1.0.5 - Fixed search shortcut.
- Updated the search URL to reflect a recent Sourcegraph.com change.
diff --git a/README.md b/README.md
index c8387cd..735b4c3 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,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
diff --git a/keymaps/sourcegraph.json b/keymaps/sourcegraph.json
index 3c78b66..0a95bbc 100644
--- a/keymaps/sourcegraph.json
+++ b/keymaps/sourcegraph.json
@@ -1,6 +1,7 @@
{
"atom-workspace": {
"alt-a": "sourcegraph:open",
- "alt-s": "sourcegraph:search"
+ "alt-s": "sourcegraph:search",
+ "alt-c": "sourcegraph:copy"
}
}
diff --git a/lib/sourcegraph.js b/lib/sourcegraph.js
index 02aac35..57d11cd 100644
--- a/lib/sourcegraph.js
+++ b/lib/sourcegraph.js
@@ -3,6 +3,7 @@
import { CompositeDisposable } from 'atom'
const opn = require('opn')
+const copy = require('copy')
const execa = require('execa')
const url = require('url')
const path = require('path')
@@ -97,7 +98,7 @@ async function open() {
}
// Open in browser.
- opn(`${sourcegraphURL()}-/editor`
+ copy(`${sourcegraphURL()}-/editor`
+ `?remote_url=${encodeURIComponent(remoteURL)}`
+ `&branch=${encodeURIComponent(branch)}`
+ `&file=${encodeURIComponent(fileRel)}`
@@ -134,6 +135,35 @@ async function search() {
+ `&search=${encodeURIComponent(query)}`)
}
+async function copy() {
+ let editor = atom.workspace.getActiveTextEditor()
+ if (!editor) {
+ return
+ }
+ let r = editor.getSelectedBufferRange()
+
+ const [remoteURL, branch, fileRel] = await repoInfo(editor.getPath())
+ if (remoteURL == "") {
+ return
+ }
+
+ // Open in browser.
+ opn(`${sourcegraphURL()}-/editor`
+ + `?remote_url=${encodeURIComponent(remoteURL)}`
+ + `&branch=${encodeURIComponent(branch)}`
+ + `&file=${encodeURIComponent(fileRel)}`
+ + `&editor=${encodeURIComponent("Atom")}`
+ + `&version=${encodeURIComponent(VERSION)}`
+ + `&start_row=${encodeURIComponent(r.start.row)}`
+ + `&start_col=${encodeURIComponent(r.start.column)}`
+ + `&end_row=${encodeURIComponent(r.end.row)}`
+ + `&end_col=${encodeURIComponent(r.end.column)}`)
+}
+
+async function edit() {
+
+}
+
export default {
config: {