Created
August 31, 2015 03:47
-
-
Save toctan/e8bb21bb97a963c140e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defun get-repo-url (arg) | |
(let* ((remote (if arg "upstream" (nth 2 (s-split "/" (magit-get-tracked-ref))))) | |
(remote-url (magit-get "remote" remote "url")) | |
(fragments (s-split "[:/@]/?/?" (s-chop-suffix ".git" remote-url)))) | |
(concat "http://" (s-join "/" (cdr fragments))))) | |
(defun open-in-repo (arg) | |
(interactive "P") | |
(let* ((url (get-repo-url arg)) | |
(branch (if arg "master" (magit-get-current-branch))) | |
(file (buffer-file-name (current-buffer))) | |
(fragment (if file "blob" "tree")) | |
(path (magit-file-relative-name (or file default-directory))) | |
(line (if file (concat "#L" (number-to-string (line-number-at-pos))) ""))) | |
(browse-url (concat (s-join "/" (list url fragment branch path)) line)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment