Skip to content

Instantly share code, notes, and snippets.

@jpmonettas
Created June 24, 2018 23:09
Show Gist options
  • Save jpmonettas/befda7d6b169afa3d55b9addf8fc77b6 to your computer and use it in GitHub Desktop.
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.
(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