├── .gitignore
├── README.md
├── image
├── open-github.png
└── select-region.png
├── make-github-url-from-file
└── open-github-from-here.el
/.gitignore:
--------------------------------------------------------------------------------
1 | *.elc
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # open-github-from-here.el
2 |
3 | ## Introduction
4 | open-github-from-here is interface to open github file url from emacs, such as https://github.com/shibayu36/emacs-open-github-from-here/blob/development/open-github-from-here.el#L41..L57
5 |
6 | ## Screenshot
7 |
8 | Select region as following,
9 |
10 |
11 |
12 | And `M-x open-github-from-here`
13 |
14 | Then open github file URL
15 |
16 |
17 |
18 | ## Requirements
19 |
20 | * system perl
21 | * git
22 |
23 | ## Installation
24 |
25 | You can install `open-github-from-here.el` from el-get.
26 |
27 | Add following to your el-get-sources setting and execute `M-x el-get-install open-github-from-here`
28 |
29 | (setq el-get-sources
30 | '(
31 | (:name open-github-from-here
32 | :type github
33 | :description "open github from here"
34 | :url "https://github.com/shibayu36/emacs-open-github-from-here")
35 | ))
36 |
37 | You also install by not using el-get. git clone this repository to your emacs lisp directory.
38 |
39 | ```
40 | $ git clone git://github.com/shibayu36/emacs-open-github-from-here.git path/to/dir
41 | ```
42 |
43 | And add the directory to load-path.
44 | ```
45 | (setq load-path
46 | (append
47 | (list
48 | (expand-file-name "path/to/dir"))
49 | load-path))
50 | ```
51 |
52 | ## Commands
53 |
54 | `open-github-from-here.el` provides following commands.
55 |
56 | ### `open-github-from-here`
57 |
58 | open github file url from select region.
--------------------------------------------------------------------------------
/image/open-github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shibayu36/emacs-open-github-from-here/0a8730c54e06525d2031501bb16bc21c69ea6c34/image/open-github.png
--------------------------------------------------------------------------------
/image/select-region.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shibayu36/emacs-open-github-from-here/0a8730c54e06525d2031501bb16bc21c69ea6c34/image/select-region.png
--------------------------------------------------------------------------------
/make-github-url-from-file:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 | use strict;
3 | use warnings;
4 |
5 | use Cwd;
6 |
7 | my $arg = shift @ARGV || "";
8 | my $filename = getcwd() . "/" . $arg; # absolute path
9 | my $line_start = shift @ARGV;
10 | my $line_end = shift @ARGV;
11 |
12 | my $host = qx{git config --get hub.host} || "github.com";
13 | chomp $host;
14 |
15 | my ($remote_url) = qx{git config --get remote.origin.url};
16 | chomp $remote_url;
17 | my ($user, $repo) = $remote_url =~ qr{[:/]([^/]+)/([^/]+?)(?:[.]git)?$};
18 |
19 | my $branch = qx{git symbolic-ref HEAD 2> /dev/null};
20 | $branch =~ s{^refs/heads/}{};
21 | chomp($branch);
22 |
23 | my $git_top = qx{git rev-parse --show-toplevel};
24 | chomp $git_top;
25 |
26 | $filename =~ s{^$git_top/}{};
27 |
28 | my $url = "https://$host/$user/$repo/tree/$branch/$filename";
29 | $url .= "#L$line_start" if $line_start;
30 | $url .= "..L$line_end" if $line_end;
31 |
32 | print $url;
33 |
--------------------------------------------------------------------------------
/open-github-from-here.el:
--------------------------------------------------------------------------------
1 | ;;; open-github-from-here.el ---
2 |
3 | ;; Copyright (C) 2013 by Yuki SHIBAZAKI
4 |
5 | ;; Author: Yuki SHIBAZAKI
6 | ;; URL:
7 | ;; Version: 0.01
8 |
9 | ;; This program is free software; you can redistribute it and/or modify
10 | ;; it under the terms of the GNU General Public License as published by
11 | ;; the Free Software Foundation, either version 3 of the License, or
12 | ;; (at your option) any later version.
13 |
14 | ;; This program is distributed in the hope that it will be useful,
15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ;; GNU General Public License for more details.
18 |
19 | ;; You should have received a copy of the GNU General Public License
20 | ;; along with this program. If not, see .
21 |
22 | ;;; Commentary:
23 |
24 | ;; open-github-from-here is to open github file url from emacs,
25 | ;; such as https://github.com/shibayu36/emacs-open-github-from-here/blob/development/open-github-from-here.el#L31..L35.
26 | ;; select region, and M-x open-github-from-here
27 |
28 | ;; To use this package, add these lines to your init.el or .emacs file:
29 | ;; (require 'open-github-from-here)
30 |
31 | ;;; Code:
32 |
33 | (defvar open-github-from-here:command-dir
34 | (if load-file-name
35 | (file-name-directory load-file-name)
36 | default-directory))
37 |
38 | (defvar open-github-from-here:command
39 | (expand-file-name "make-github-url-from-file" open-github-from-here:command-dir))
40 |
41 | (defun open-github-from-here ()
42 | (interactive)
43 | (let ((github-url))
44 | (cond ((and (open-github-from-here:git-project-p) (use-region-p))
45 | (setq github-url (shell-command-to-string
46 | (format "%s %s %d %d"
47 | open-github-from-here:command
48 | (file-name-nondirectory (buffer-file-name))
49 | (line-number-at-pos (region-beginning))
50 | (line-number-at-pos (region-end))))))
51 | ((open-github-from-here:git-project-p)
52 | (setq github-url (shell-command-to-string
53 | (format "%s %s"
54 | open-github-from-here:command
55 | (file-name-nondirectory (buffer-file-name)))))))
56 | (browse-url github-url)))
57 |
58 | (defun open-github-from-here:chomp (str)
59 | (replace-regexp-in-string "[\n\r]+$" "" str))
60 |
61 | (defun open-github-from-here:git-project-p ()
62 | (string=
63 | (open-github-from-here:chomp
64 | (shell-command-to-string "git rev-parse --is-inside-work-tree"))
65 | "true"))
66 |
67 | (provide 'open-github-from-here)
68 |
69 | ;;; open-github-from-here.el ends here
70 |
--------------------------------------------------------------------------------