Created
June 24, 2018 23:09
-
-
Save jpmonettas/befda7d6b169afa3d55b9addf8fc77b6 to your computer and use it in GitHub Desktop.
Quickly share a github link of what you are seeing in a buffer. Yanks a link you can paste in the browser.
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 yank-github-link () | |
"Quickly share a github link of what you are seeing in a buffer. Yanks | |
a link you can paste in the browser." | |
(interactive) | |
(let* ((remote (or (magit-get-push-remote) "origin")) | |
(url (magit-get "remote" remote "url")) | |
(project (if (string-prefix-p "git" url) | |
(substring url 15 -4) ;; git link | |
(substring url 19 -4))) ;; https link | |
(link (format "https://github.com/%s/blob/%s/%s#L%d" | |
project | |
(magit-get-current-branch) | |
(magit-current-file) | |
(count-lines 1 (point))))) | |
(kill-new link))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment