Skip to content

Instantly share code, notes, and snippets.

@drobune
Created September 5, 2015 21:01
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save drobune/0a262af74b1e34414759 to your computer and use it in GitHub Desktop.
emacsでカーソル行のgithubページに飛ぶ
(defun jump-to-github ()
"Go to github code position at most recent commitl;"
(interactive)
(let (full_path)
(setq
full_path buffer-file-name
dir_name (shell-command-to-string (concat "echo " full_path "| xargs dirname"))
cd_dir (shell-command-to-string (concat "cd " dir_name))
prefix (shell-command-to-string "git rev-parse --show-prefix | tr -d '\n'")
current_commit (shell-command-to-string "git show -s --format=%H | tr -d '\n'")
current_line (count-lines 1 (point))
repo_name (shell-command-to-string "git remote -v | grep origin | head -1 | awk '{sub(\"git@github.com:\",\"\");sub(\".git\",\"\");print $2}' | tr -d '\n'")
github_url (concat "https://github.com/"
repo_name "/blob/" current_commit "/"
prefix (buffer-name) "#L" (number-to-string current_line)))
(shell-command (concat "xdg-open " github_url))))
(global-set-key (kbd "M-b") 'jump-to-github)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment