feat(SublimeText2.GitPackages): cache packages
This commit is contained in:
1
EthanBrown.SublimeText2.GitPackages/tools/PackageCache/GitHubinator/.gitignore
vendored
Normal file
1
EthanBrown.SublimeText2.GitPackages/tools/PackageCache/GitHubinator/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.pyc
|
@@ -0,0 +1,6 @@
|
||||
[
|
||||
{ "command": "githubinator", "caption": "GitHubinator", "args": { "permalink": false } },
|
||||
{ "command": "githubinator", "caption": "GitHubinator Permalink", "args": { "permalink": true } },
|
||||
{ "command": "githubinator", "caption": "GitHubinator Blame", "args": { "permalink": false, "mode": "blame" } },
|
||||
{ "command": "githubinator", "caption": "GitHubinator Blame Permalink", "args": { "permalink": true, "mode": "blame" } }
|
||||
]
|
@@ -0,0 +1,4 @@
|
||||
[
|
||||
{ "keys": ["super+\\"], "command": "githubinator", "args" : { "permalink": false }},
|
||||
{ "keys": ["shift+super+\\"], "command": "githubinator", "args" : { "permalink": true }}
|
||||
]
|
@@ -0,0 +1,22 @@
|
||||
[
|
||||
{
|
||||
"caption": "GitHubinator",
|
||||
"command": "githubinator",
|
||||
"args": { "permalink": false }
|
||||
},
|
||||
{
|
||||
"caption": "GitHubinator Permalink",
|
||||
"command": "githubinator",
|
||||
"args": { "permalink": true }
|
||||
},
|
||||
{
|
||||
"caption": "GitHubinator Blame",
|
||||
"command": "githubinator",
|
||||
"args": { "permalink": false, "mode": "blame" }
|
||||
},
|
||||
{
|
||||
"caption": "GitHubinator Blame Permalink",
|
||||
"command": "githubinator",
|
||||
"args": { "permalink": true, "mode": "blame" }
|
||||
}
|
||||
]
|
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"default_remote": "origin"
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
# GitHubinator*
|
||||
|
||||
*_With regards to [Dr. Heinz Doofenshmirtz](http://en.wikipedia.org/wiki/Dr._Heinz_Doofenshmirtz)_
|
||||
|
||||
This will allow you to select text in a Sublime Text 2 file, and see the highlighted lines on GitHub's remote repo, if one exists.
|
||||
|
||||

|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
If you use [Package Control](http://wbond.net/sublime_packages/package_control), just install it from there. If not:
|
||||
|
||||
Clone this repo to your Sublime Text 2 Packages folder:
|
||||
|
||||
cd ~/"Library/Application Support/Sublime Text 2/Packages/"
|
||||
git clone https://github.com/ehamiter/ST2-GitHubinator.git
|
||||
|
||||
The plugin should be picked up automatically. If not, restart Sublime Text.
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
The defaults should work for most setups, but if you have a different remote name, you can configure it in the `Githubinator.sublime-settings` file:
|
||||
|
||||
{
|
||||
"default_remote": "origin"
|
||||
}
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Select some text.
|
||||
Activate the context menu and select "GitHubinator" or by keypress (⌘\\ by default, configurable in .sublime-keymap file).
|
@@ -0,0 +1,76 @@
|
||||
import os
|
||||
import re
|
||||
import sublime
|
||||
import sublime_plugin
|
||||
|
||||
|
||||
class GithubinatorCommand(sublime_plugin.TextCommand):
|
||||
'''This will allow you to highlight your code, activate the plugin, then see the
|
||||
highlighted results on GitHub.
|
||||
'''
|
||||
|
||||
def load_config(self):
|
||||
s = sublime.load_settings("Githubinator.sublime-settings")
|
||||
global DEFAULT_GIT_REMOTE; DEFAULT_GIT_REMOTE = s.get("default_remote")
|
||||
|
||||
def run(self, edit, permalink = False, mode = 'blob'):
|
||||
self.load_config()
|
||||
if not self.view.file_name():
|
||||
return
|
||||
|
||||
full_name = os.path.realpath(self.view.file_name())
|
||||
folder_name, file_name = os.path.split(full_name)
|
||||
|
||||
git_path = self.recurse_dir(folder_name, '.git')
|
||||
if not git_path:
|
||||
sublime.status_message('Could not find .git directory.')
|
||||
print('Could not find .git directory.')
|
||||
return
|
||||
|
||||
git_config_path = os.path.join(git_path, '.git', 'config')
|
||||
new_git_path = folder_name[len(git_path):]
|
||||
|
||||
with open(git_config_path, "r") as git_config_file:
|
||||
config = git_config_file.read()
|
||||
|
||||
sel = self.view.sel()[0]
|
||||
begin_line = self.view.rowcol(sel.begin())[0] + 1
|
||||
end_line = self.view.rowcol(sel.end())[0] + 1
|
||||
if begin_line == end_line:
|
||||
lines = begin_line
|
||||
else:
|
||||
lines = '%s-%s' % (begin_line, end_line)
|
||||
|
||||
for remote in [DEFAULT_GIT_REMOTE]:
|
||||
regex = r'.*\s.*(?:https://github\.com/|github\.com:|git://github\.com/)(.*)/(.*?)(?:\.git)?\r?\n'
|
||||
result = re.search(remote + regex, config)
|
||||
if not result:
|
||||
continue
|
||||
matches = result.groups()
|
||||
|
||||
ref_path = open(os.path.join(git_path, '.git', 'HEAD'), "r").read().replace('ref: ', '')[:-1]
|
||||
branch = ref_path.replace('refs/heads/','')
|
||||
sha = open(os.path.join(git_path, '.git', ref_path), "r").read()[:-1]
|
||||
target = sha if permalink else branch
|
||||
|
||||
full_link = 'https://github.com/%s/%s/%s/%s%s/%s#L%s' % \
|
||||
(matches[0], matches[1], mode, target, new_git_path, file_name, lines)
|
||||
sublime.set_clipboard(full_link)
|
||||
sublime.status_message('Copied %s to clipboard.' % full_link)
|
||||
print('Copied %s to clipboard.' % full_link)
|
||||
self.view.window().run_command('open_url', {"url": full_link})
|
||||
break
|
||||
|
||||
|
||||
def recurse_dir(self, path, folder):
|
||||
items = os.listdir(path)
|
||||
if folder in items and os.path.isdir(os.path.join(path, folder)):
|
||||
return path
|
||||
dirname = os.path.dirname(path)
|
||||
if dirname == path:
|
||||
return None
|
||||
return self.recurse_dir(dirname, folder)
|
||||
|
||||
|
||||
def is_enabled(self):
|
||||
return self.view.file_name() and len(self.view.file_name()) > 0
|
@@ -0,0 +1 @@
|
||||
{"url": "https://github.com/ehamiter/ST2-GitHubinator", "version": "2013.03.02.08.48.58", "description": "Sublime Text 2 plugin that shows selected ST2 text on GitHub"}
|
Reference in New Issue
Block a user