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
3 changes: 3 additions & 0 deletions Preferences.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"gitblame.scheme": "dark"
}
45 changes: 33 additions & 12 deletions git-blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,35 @@
from subprocess import check_output as shell


blame_cache = {}
template = '''
<span>
template_scheme = {}
template_scheme['light'] = '''
<style>
span {{
span {
background-color: #aee;
color: #444;
}
strong, a {
text-decoration: none;
color: #000;
}
</style>
'''
template_scheme['dark'] = '''
<style>
span {
background-color: brown;
}}
a {{
}
a {
text-decoration: none;
}}
}
</style>
'''

template = '''
<span>
{scheme}
<strong>Git Blame:</strong> ({user})
Updated: {date} {time} |
Updated: {date} {time} |
<a href="copy-{sha}">[{sha}]</a> |
<a href="close">
<close>X</close>&nbsp;
Expand Down Expand Up @@ -58,7 +74,7 @@ def parse_blame(self, blame):
file_path = None

# Fix an issue where the username has a space
# Im going to need to do something better though if people
# Im going to need to do something better though if people
# start to have multiple spaces in their names.
if not isinstance(date[0], int):
user = "{0} {1}".format(user, date)
Expand All @@ -70,7 +86,7 @@ def on_phantom_close(self, href):
if href.startswith('copy'):
sha = href.replace('copy-','')
sublime.set_clipboard(sha)

self.view.erase_phantoms('git-blame')


Expand All @@ -82,13 +98,18 @@ def run(self, edit):
line = self.view.line(region)
(row, col) = self.view.rowcol(region.begin())
full_path = self.view.file_name()
result = self.get_blame(int(row)+1, full_path)
result = self.get_blame(int(row) + 1, full_path)
if not result:
# Unable to get blame
return

sha, user, date, time = self.parse_blame(result)
body = template.format(sha=sha, user=user, date=date, time=time)

settings = sublime.load_settings('Preferences.sublime-settings')
scheme_color = settings.get('gitblame.scheme') or 'dark'

body = template.format(sha=sha, user=user, date=date, time=time,
scheme=template_scheme.get(scheme_color, ''))

phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close)
phantoms.append(phantom)
Expand Down