Created
February 11, 2016 11:12
-
-
Save chmouel/33ed0f000bcf674e2643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Adapted from https://gist.github.com/ieure/883725 for magit-log | |
(eval-after-load "magit" | |
'(progn | |
(defun magit-log-browse-github-commit (commit) | |
"Open a browser pointing to the current commit on GitHub. | |
With prefix argument, go to the commit HEAD is at." | |
(interactive "p") | |
(let* ((branch (magit-get-current-branch)) | |
(remote (and branch (magit-get "branch" branch "remote"))) | |
(remote-url (magit-get "remote" remote "url")) | |
(current-commit (magit-commit-at-point))) | |
(browse-url | |
(cond ((string-match "git@github\\.com" remote-url) | |
(replace-regexp-in-string | |
"^[email protected]:\\(.*?\\)\\(\\.git\\)?$" | |
(format "https://github.com/\\1/commit/%s" current-commit) | |
remote-url)) | |
((string-match "https?://github\\.com" remote-url) | |
(replace-regexp-in-string | |
"^\\(https?://github\\.com/.*?\\)\\(\\.git\\)?$" | |
(format "\\1/commit/%s" current-commit) remote-url)) | |
(t (error "Tracked branch is not on GitHub.")))))) | |
(define-key magit-log-mode-map "\C-cb" 'magit-log-browse-github-commit))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment