Skip to content

Instantly share code, notes, and snippets.

@masatomo
Forked from dagezi/github-url.el
Last active December 31, 2015 09:58
Show Gist options
  • Select an option

  • Save masatomo/7969868 to your computer and use it in GitHub Desktop.

Select an option

Save masatomo/7969868 to your computer and use it in GitHub Desktop.

Revisions

  1. masatomo revised this gist Dec 26, 2013. 1 changed file with 1 addition and 39 deletions.
    40 changes: 1 addition & 39 deletions github-url.el
    Original file line number Diff line number Diff line change
    @@ -1,39 +1 @@
    (defun github-url-decompose (file &optional partial)
    (cond
    ((file-directory-p (expand-file-name ".git" file)) (cons file partial))
    ((equal "/" file) nil)
    (t (github-url-decompose (directory-file-name (file-name-directory file))
    (if partial
    (concat (file-name-nondirectory file) "/" partial)
    (file-name-nondirectory file))))))

    (defun github-url-get-origin (dir)
    (with-temp-buffer
    (insert-file-contents (expand-file-name ".git/config" dir))
    (save-match-data
    (search-forward "[remote \"origin\"]")
    (let ((end (save-excursion (re-search-forward "^\\[" nil 'to-end) (point))))
    (and (re-search-forward "url *= *\\(git@\\|https://\\)github\\.com\\(/\\|:\\)\\([a-zA-Z\\/-_]*\\)\\>" end)
    (match-string 3))))))

    (defun github-url (start end)
    (interactive "r")
    (let ((g (github-url-decompose (buffer-file-name)))
    rootdir file origin url start-line end-line)
    (unless g
    (error "Not managed by git: %s" default-directory))
    (setq rootdir (car g)
    file (cdr g))
    (setq origin (github-url-get-origin rootdir))
    (setq start-line (line-number-at-pos start))
    (setq end-line (line-number-at-pos end))
    (setq url (format "https://github.com/%s/blob/master/%s#L%d-L%d"
    origin file start-line end-line))
    (message "URL: %s" url)

    (let* ((process-connection-type nil)
    (proc (start-process "pbcopy" nil "pbcopy")))
    (process-send-string proc url)
    (process-send-eof proc))

    (kill-new url)))
    moved to https://github.com/quipper/github-url.el
  2. masatomo revised this gist Dec 26, 2013. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions github-url.el
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    ((file-directory-p (expand-file-name ".git" file)) (cons file partial))
    ((equal "/" file) nil)
    (t (github-url-decompose (directory-file-name (file-name-directory file))
    (if partial
    (if partial
    (concat (file-name-nondirectory file) "/" partial)
    (file-name-nondirectory file))))))

    @@ -13,8 +13,8 @@
    (save-match-data
    (search-forward "[remote \"origin\"]")
    (let ((end (save-excursion (re-search-forward "^\\[" nil 'to-end) (point))))
    (and (re-search-forward "url *= *git@github\\.com:\\(.*\\)\\.git\\>" end)
    (match-string 1))))))
    (and (re-search-forward "url *= *\\(git@\\|https://\\)github\\.com\\(/\\|:\\)\\([a-zA-Z\\/-_]*\\)\\>" end)
    (match-string 3))))))

    (defun github-url (start end)
    (interactive "r")
    @@ -29,11 +29,11 @@
    (setq end-line (line-number-at-pos end))
    (setq url (format "https://github.com/%s/blob/master/%s#L%d-L%d"
    origin file start-line end-line))

    (message "URL: %s" url)
    (let* ((process-connection-type nil)

    (let* ((process-connection-type nil)
    (proc (start-process "pbcopy" nil "pbcopy")))
    (process-send-string proc url)
    (process-send-eof proc))
    (kill-new url)))

    (kill-new url)))
  3. masatomo revised this gist Dec 15, 2013. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions github-url.el
    Original file line number Diff line number Diff line change
    @@ -29,5 +29,11 @@
    (setq end-line (line-number-at-pos end))
    (setq url (format "https://github.com/%s/blob/master/%s#L%d-L%d"
    origin file start-line end-line))

    (message "URL: %s" url)
    (let* ((process-connection-type nil)
    (proc (start-process "pbcopy" nil "pbcopy")))
    (process-send-string proc url)
    (process-send-eof proc))

    (kill-new url)))
  4. @dagezi dagezi revised this gist Dec 10, 2013. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions github-url.el
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@

    (defun github-url (start end)
    (interactive "r")
    (let ((g (github-url-decompose default-directory))
    (let ((g (github-url-decompose (buffer-file-name)))
    rootdir file origin url start-line end-line)
    (unless g
    (error "Not managed by git: %s" default-directory))
    @@ -31,6 +31,3 @@
    origin file start-line end-line))
    (message "URL: %s" url)
    (kill-new url)))



  5. @dagezi dagezi created this gist Dec 10, 2013.
    36 changes: 36 additions & 0 deletions github-url.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    (defun github-url-decompose (file &optional partial)
    (cond
    ((file-directory-p (expand-file-name ".git" file)) (cons file partial))
    ((equal "/" file) nil)
    (t (github-url-decompose (directory-file-name (file-name-directory file))
    (if partial
    (concat (file-name-nondirectory file) "/" partial)
    (file-name-nondirectory file))))))

    (defun github-url-get-origin (dir)
    (with-temp-buffer
    (insert-file-contents (expand-file-name ".git/config" dir))
    (save-match-data
    (search-forward "[remote \"origin\"]")
    (let ((end (save-excursion (re-search-forward "^\\[" nil 'to-end) (point))))
    (and (re-search-forward "url *= *git@github\\.com:\\(.*\\)\\.git\\>" end)
    (match-string 1))))))

    (defun github-url (start end)
    (interactive "r")
    (let ((g (github-url-decompose default-directory))
    rootdir file origin url start-line end-line)
    (unless g
    (error "Not managed by git: %s" default-directory))
    (setq rootdir (car g)
    file (cdr g))
    (setq origin (github-url-get-origin rootdir))
    (setq start-line (line-number-at-pos start))
    (setq end-line (line-number-at-pos end))
    (setq url (format "https://github.com/%s/blob/master/%s#L%d-L%d"
    origin file start-line end-line))
    (message "URL: %s" url)
    (kill-new url)))