Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defun jump-to-github ()
"Go to github code position at most recent commitl;"
(let (full_path)
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(\"\",\"\");sub(\".git\",\"\");print $2}' | tr -d '\n'")
github_url (concat ""
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
You can’t perform that action at this time.