Skip to content

Instantly share code, notes, and snippets.

@ivey
Created August 20, 2009 05:05
Show Gist options
  • Save ivey/170852 to your computer and use it in GitHub Desktop.
Save ivey/170852 to your computer and use it in GitHub Desktop.
(defun depth-from-git-root ()
(length (split-string
(shell-command-to-string "git rev-parse --show-cdup")
"/")))
(defun relative-file-name ()
(mapconcat 'identity (last
(split-string (buffer-file-name) "/")
(depth-from-git-root))
"/"))
(defun my-filter (condp lst)
(delq nil
(mapcar (lambda (x) (and (funcall condp x) x)) lst)))
(defun current-branchp (branch)
(if (string-match "^\\* " branch)
t nil))
(defun current-git-branch ()
(substring
(car (my-filter 'current-branchp
(split-string (shell-command-to-string "git branch") "\n")))
2))
(defun github-repo ()
(substring
(replace-regexp-in-string
".*:" ""
(shell-command-to-string "git config remote.origin.url"))
0 -5))
(defun github-url ()
(concat
"http://github.com/" (github-repo) "/blob/"
(current-git-branch) "/" (relative-file-name)))
(defun open-file-in-github ()
(interactive)
(browse-url (github-url)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment