• Stars
    star
    394
  • Rank 109,295 (Top 3 %)
  • Language
    Emacs Lisp
  • Created almost 11 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Emacs package to get the GitHub/Bitbucket/GitLab/... URL for a buffer location

git-link

MELPA Build Status

Interactive Emacs functions that create URLs for files and commits in GitHub/Bitbucket/GitLab/... repositories.

git-link returns the URL for the current buffer's file location at the current line number or active region.

git-link-commit returns the URL for the commit at point.

git-link-homepage returns the URL for the repository's homepage.

URLs are added to the kill ring.

Usage

Functions can be called interactively (M-x git-link) or via a key binding of your choice. For example:

(global-set-key (kbd "C-c g l") 'git-link)

With a single prefix argument prompt for the remote's name. Defaults to "origin".

With a double prefix argument invert the value of git-link-use-commit.

With a prefix argument of -, generate a link without line numbers.

Works with Dired, Magit, VC revisions, and Tramp too.

Settings

Global setting are elisp variables. They can be set directly or via M-x customize.

Local settings are managed via the repository's git configuration. They can be set via:

git config --local --add setting value

Local settings have precedence over global settings.

Global

git-link-default-remote

Name of the remote to link to, defaults to nil.

git-link-default-branch

Name of the remote branch to link to, defaults to the current branch.

git-link-open-in-browser

If t also open the link via browse-url. To use an alternate function set to that function's symbol. Defaults to nil.

git-link-use-commit

If non-nil use the latest commit's hash in the link instead of the branch name, defaults to nil.

git-link-use-single-line-number

If nil line numbers are only added when the selection contains more than 1 line, defaults to t.

Note that git-link will exclude line numbers when invoked with the - prefix argument.

Local

git-link.remote

Name of the remote to link to.

git-link.branch

Name of the remote branch to link to.

Supported Services

Git Timemachine

If git-timemachine-mode is active git-link generates a URL for the version of the file being visited.

Sourcegraph

To link to files on a Sourcegraph server add a git remote pointing to the repository's Sourcegraph page:

git remote add sourcegraph https://sourcegraph.com/github.com/sshaw/copy-as-format

Links can be generated by specifying sourcegraph as your remote when calling the desired link function or by setting sourcegraph as the default remote.

Note that the remote can be named anything but its URL's host must match what's in the associated link function's alist. This defaults to "sourcegraph" but can be changed. See Building Links and Adding Services.

URLs with ports or an http scheme will not work. It's a trivial fix so if it's a problem for you please open an issue.

Building Links and Adding Services

git-link-remote-alist is an alist containing (REGEXP FUNCTION) elements. The FUNCTION creates URLs for file on remote host names that match the REGEXP. To add (or modify) how URLs are created for a given host, add appropriate elements to this list.

As an example, one of the default elements in this alist is ("gitlab" git-link-gitlab). So the git-link-gitlab function will be used to create URLs to files in remotes that match the regexp "gitlab". That would cover common Gitlab host URLs like "gitlab.com", "gitlab.example.com" and "gitlab.example.org".

git-link-commit-remote-alist is also an alist containing (REGEXP FUNCTION) elements. Here, the FUNCTION creates URLs to the commit pages, for remote hosts matching REGEXP.

If you use a self-hosted version of one of the supported services, but your remote URL does match with the defaults, you can configure these link function alists. For example, for a GitHub Enterprise instance at gh.example.com, you could add the following to your .emacs file:

(eval-after-load 'git-link
 '(progn
   (add-to-list 'git-link-remote-alist
     '("gh\\.example\\.com" git-link-github))
   (add-to-list 'git-link-commit-remote-alist
     '("gh\\.example\\.com" git-link-commit-github))))

The git-link signature is:

HOSTNAME DIRNAME FILENAME BRANCH COMMIT START END

  • HOSTNAME hostname of the remote
  • DIRNAME directory portion of the remote
  • FILENAME source file, relative to DIRNAME
  • BRANCH active branch, may be nil if the repo's in "detached HEAD" state
  • COMMIT SHA of the latest commit
  • START starting line number
  • END ending line number, nil unless region is active

The git-link-commit signature is:

HOSTNAME DIRNAME COMMIT

  • HOSTNAME hostname of the remote
  • DIRNAME directory portion of the remote
  • COMMIT SHA of the commit

See Also

TODO

  • More tests!
  • Consolidate git-link-*-alists
  • git-link-grep

More Repositories

1

copy-as-format

Emacs function to copy buffer locations as GitHub/Slack/JIRA etc... formatted code
Emacs Lisp
138
star
2

itunes_store_transporter

Upload and manage your assets in the iTunes Store using the iTunes Store’s Transporter (iTMSTransporter).
Ruby
118
star
3

export-pull-requests

Export pull requests and/or issues to a CSV file. Supports GitHub, GitLab, and Bitbucket
Ruby
109
star
4

itunes_store_transporter_web

iTunes Store Transporter GUI: GUI and workflow automation for the iTunes Store’s Transporter (iTMSTransporter)
Ruby
80
star
5

yymmdd

Tiny DSL for idiomatic date parsing and formatting in Ruby
Ruby
77
star
6

normalize_country

Convert country names and codes to a standard.
Ruby
67
star
7

ddex

DDEX metadata serialization for Ruby
Ruby
53
star
8

build-status

Emacs minor mode that monitors and shows a buffer's build status in the mode line.
Emacs Lisp
27
star
9

class2

Easily create Ruby class hierarchies that support nested attributes, type conversion, serialization, equality, and more.
Ruby
14
star
10

output-as-format

Output stdin as GitHub/Slack/Jira etc... formatted code, lists, or quotes
Perl
13
star
11

jaxb2ruby

Generate pure Ruby objects from an XML schema (XSD) using JAXB and JRuby. Use your favorite XML to object mapper or a custom ERB template.
Ruby
12
star
12

batchlabels

Add or remove labels in batches to/from GitHub issues and pull requests.
Go
8
star
13

angry_raise

raise Ruby exceptions, with emotion and intensity
Ruby
6
star
14

optout

The opposite of getopt(): validate an option hash and turn it into something appropriate for exec() and system()-like functions
Ruby
5
star
15

URI-fasp

URI handler for Aspera's FASP protocol
Perl
5
star
16

transform_legacy_attribute_methods

A Rails plugin that allows you to transform your ActiveRecord model's "legacy" attribute methods into attribute aliases that can be used in dynamic finders and attribute hashes.
Ruby
5
star
17

Time-Timecode

Video timecode class for Perl and command line program. Supports any frame rate, conversions, drop/non-drop frame counts and more.
Perl
5
star
18

issue-link

Get the link to JIRA/Tracker/GitHub issues. Turn bug/feature/issue IDs into links.
Emacs Lisp
4
star
19

ruby-factory-mode

Emacs minor mode for Ruby test object generation libraries
Emacs Lisp
3
star
20

Mojolicious-Plugin-FormFields

Use objects and data structures in your forms
Perl
3
star
21

dotfiles

My dotfiles. Everything but Emacs, which has its own repository: https://github.com/sshaw/emacs.d
Shell
3
star
22

ruby-jing

RELAX NG schema validation in Ruby using the Jing CLI
Ruby
3
star
23

xslt-timecode

A pure, dependency free, XSLT 1.0 library for video timecode manipulation
XSLT
2
star
24

glc

The GitHub Link Checker. Monitor GitHub activity for links that aren't permanent, and do something.
Go
2
star
25

interrobang

Did the method end with "?" or "!"‽ Interrobang gives you the best of both worlds‽
Ruby
2
star
26

selfie_formatter

The RSpec Selfie Formatter: A Formatter that takes photos of you while your tests run and uses them to track progress and format the results.
Ruby
2
star
27

jquery-selectunique

Given a group of select fields with the same options, SelectUnique will remove an option from the other select fields when it's selected, and put it back when it's changed.
JavaScript
2
star
28

Mojolicious-Plugin-ParamExpand

Turns request parameters into nested data structures using CGI::Expand.
Perl
1
star
29

logging-honeybadger

Honeybadger appender for the Logging gem
Ruby
1
star
30

logging-appenders-airbrake

Airbrake appender for the Logging gem
Ruby
1
star
31

markdown_usage

Output a colorized version of your program's usage using a Markdown document embedded in your script, from your project's README, or anywhere else.
Ruby
1
star
32

page_number

Page number validation. Utility methods for pagination page and per page that make sure you'll always have a valid number
Ruby
1
star
33

require3

Kernel#require something and make it accessible via a different namespace.
Ruby
1
star
34

alias2

Make classes, modules, and constants accessible via a different namespace.
Ruby
1
star
35

keep_defaults

Prevent ActiveRecord attributes for not null columns with default values from being set to nil.
Ruby
1
star
36

emacs.d

My Emacs config
Emacs Lisp
1
star
37

select-unique

Given a group of HTML select elements with the same options, Select Unique will remove an option from the other select elements when it's selected, and put it back when it's changed.
JavaScript
1
star
38

Mojolicious-Command-secret

Generate a secret() using random bytes and add it to your app
Perl
1
star
39

Mojolicious-Plugin-DigestAuth

HTTP Digest Authentication for Mojolicious
Perl
1
star