Skip to content

Instantly share code, notes, and snippets.

@fukamachi
Created August 14, 2013 05:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fukamachi/6228274 to your computer and use it in GitHub Desktop.
Save fukamachi/6228274 to your computer and use it in GitHub Desktop.
(defun git-blame-current-line ()
(interactive)
(let ((blame-result
(shell-command-to-string
(format "git blame -p -L %d,+1 %s" (line-number-at-pos) (buffer-file-name))))
(result (make-hash-table :test 'equal)))
(loop with (commit . lines) = (split-string blame-result "\n")
for line in lines
for (key . values) = (split-string (or line "") " ")
do (setf (gethash key result) (mapconcat 'identity values " "))
finally
(setf (gethash "commit" result) commit))
(funcall (if (fboundp 'popup-tip)
'popup-tip
'message)
(format "[%s] %s: %s (%s)"
(substring (gethash "commit" result) 0 6)
(gethash "author" result)
(gethash "summary" result)
(format-time-string "%Y/%m/%d %H:%M"
(seconds-to-time
(string-to-number (gethash "author-time" result))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment