Open Files on Github from Emacs

In the course of a project it helps to share pointers to specific files and lines of code with others. I use Github for this task, sharing URLs like: https://github.com/gleitz/howdoi/blob/master/howdoi/howdoi.py#L156

When sharing URLs from a project with deep directories (Scala/Java) it can be a real pain to open github.com, pick a branch, and then click through src/com/blah/blah folders until you find the file. Instead, use this command-line Python script to generate a Github URL directly from a file or directory. Also included is an elisp function to generate URLs from Emacs.

The URL generation logic can be found inside gitopener.py

Invoke the script on Emacs with M-x browse-on-github


;; Open github pages from files
(defun browse-on-github ()
  "Show the current file on github"
  (interactive)
  (let* ((script-path (expand-file-name "~/.emacs.d/lib/python/gleitzpy/gitopener.py"))
         (full-path (mapconcat 'identity `("python" ,script-path ,(buffer-file-name)) " "))
         (result-url (trim-string (shell-command-to-string full-path))))
    (message result-url)
    (browse-url result-url)
    ))

Update: Stand-alone project now on github.

image