Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Save draft copy function. #4

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
{
"keys": ["alt+s"],
"command": "sourcegraph_search"
},
{
"keys": ["alt+c"]
"command": ["sourcegraph_copy"]
}
]
4 changes: 4 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
{
"keys": ["option+s"],
"command": "sourcegraph_search"
},
{
"keys": ["option+c"]
"command": ["sourcegraph_copy"]
}
]
4 changes: 4 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
{
"keys": ["alt+s"],
"command": "sourcegraph_search"
},
{
"keys": ["alt+c"]
"command": ["sourcegraph_copy"]
}
]
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Keyboard Shortcuts:
|---------------------------------|---------------------|------------------|
| Open file in Sourcegraph | <kbd>Option+A</kbd> | <kbd>Alt+A</kbd> |
| Search selection in Sourcegraph | <kbd>Option+S</kbd> | <kbd>Alt+S</kbd> |

| Copy link from Sourcegraph | <kbd>Option+C</kbd> | <kbd>Alt+C</kbd> |

## Settings

Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions Sourcegraph.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@
"caption": "Sourcegraph: Search",
"command": "sourcegraph_search"
}
{
"caption": "Sourcegraph: Copy",
"command": "sourcegraph_copy"
}
]
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 4 additions & 0 deletions messages/welcome.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 37 additions & 1 deletion sourcegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand Down