Skip to content

Instantly share code, notes, and snippets.

@toctan
Created August 31, 2015 03:47
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 toctan/e8bb21bb97a963c140e4 to your computer and use it in GitHub Desktop.
Save toctan/e8bb21bb97a963c140e4 to your computer and use it in GitHub Desktop.
(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