forgelink
Generate shareable URLs to files and line ranges in hosted git repositories, from the command line.
Inspired by the Emacs package git-link.
Supported Forges
- GitHub
- GitLab
- SourceHut
- Bitbucket
- Codeberg (including forge.fedoraproject.org)
Installation
This installs a binary named forgelink.
Usage
By default forgelink generates a stable URL pinned to the current commit SHA:
Append :N for a single line or :N-M for a range:
Target a remote other than origin with --remote:
Use the current branch name instead of the commit SHA with --branch:
--branch requires HEAD to be on a named branch. It errors on a detached
HEAD, which includes Jujutsu (jj) working copies. Use the default
commit-pinned link in that case.
Generate a link to the project homepage with --project:
Copy the URL to the clipboard with --copy, which still prints it to stdout
so piping keeps working:
Open the URL in your default browser with --open, which also still prints
it. --copy and --open can be combined:
Clipboard and browser support are default-on cargo features (clipboard and
browser). Build with --no-default-features to drop the arboard and open
dependencies, which also removes the --copy and --open flags. On Linux
under X11 the clipboard is owned by the running process, so the copied URL may
not persist after forgelink exits. macOS and Windows are unaffected.
It works from any subdirectory inside the repository:
&&
You can also pass an absolute path to link to a file in any repository, regardless of your current directory:
Editor integration
forgelink takes a path:line argument and prints a URL, so any editor that can
run a shell command with the current buffer path and cursor line can bind it
directly, with no plugin required.
Helix
In ~/.config/helix/config.toml:
[]
= ":sh forgelink %{file_path_absolute}:%{cursor_line} --copy"
space o copies a link to the current line. %{file_path_absolute} is used so
it works regardless of the directory Helix was launched from.
Kakoune
In ~/.config/kak/kakrc:
define-command -docstring 'copy a forge link to the current line' forge-link %{
nop %sh{ forgelink "$kak_buffile:$kak_cursor_line" --copy }
}
map global user o ': forge-link<ret>' -docstring 'forge link'
License
Licensed under either of MIT or Apache-2.0 at your option.