Skip to content

arbourd/git-open

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git-open

git open opens the Git repository in the web browser.

Usage

Open the root of a repository.

$ git open

Open a specific file or folder of a repository.

$ git open main.go

Open a specific commit of a repository.

$ git open 7605d91

Open a specific line, or range of lines, of a file.

$ git open main.go:42
$ git open main.go:42-50

Open a different repository than cwd.

$ git -C ~/src/my-repo open

Providers

By default, four providers are supported: github.com, gitlab.com, bitbucket.org and codeberg.org.

Provider URL Commit prefix Path prefix Line format
GitHub https://github.com commit tree L%l-L%l
GitLab https://gitlab.com -/commit -/tree L%l-%l
Bitbucket https://bitbucket.org commits src lines-%l:%l
Codeberg https://codeberg.org commit tree L%l-L%l

To add custom Git providers and their URLs, set their values within the global git config.

[open "https://git.mydomain.dev"]
    commitprefix = commit
    pathprefix = tree
    lineformat = L%l-L%l

This can also be set using the git CLI.

$ git config --global open.https://git.mydomain.dev.commitprefix commit
$ git config --global open.https://git.mydomain.dev.pathprefix tree
$ git config --global open.https://git.mydomain.dev.lineformat "L%l-L%l"

commitprefix and pathprefix are used to template the URI for your provider.

fmt.Println(host + "/" + repository + "/" + commitprefix )
// https://git.mydomain.dev/<repository>/commit

fmt.Println(host + "/" + repository + "/" + pathprefix )
// https://git.mydomain.dev/<repository>/tree

lineformat templates the line anchor where %l denotes the line number. Up to two %l may be provided, denoting the start and end lines. 3 or more %l or unsupported Go-style verbs like %v will disable the line anchor templating and issue a warning.

fmt.Sprintf(lineformat, startLine)          // one %l
fmt.Sprintf(lineformat, startLine, endLine) // two %l
// L42 or L42-L50

Installation

Install with brew.

$ brew install arbourd/tap/git-open

Install with go install.

$ go install github.com/arbourd/git-open@latest

About

Opens your Git repository in your browser

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages