+
Skip to content

Portable file permalink generator written in Crystal language. Working with Kakoune and neovim out of the box.

License

Notifications You must be signed in to change notification settings

Yukaii/gitlinker.cr

Repository files navigation

Gitlinker CLI

Gitlinker is a command-line tool that generates URLs for specific lines of code in a Git repository hosted on various platforms like GitHub, GitLab, Bitbucket, and Codeberg.

Installation

To install Gitlinker, make sure you have Crystal installed on your system. Then, run the following command:

shards build --production --release --no-debug

This will compile the Gitlinker source code and generate an executable named gitlinker.

Homebrew

For Homebrew users, you can tap the repository and install the latest head version:

brew tap Yukaii/tap
brew install --head gitlinker

Usage

To use Gitlinker, run the gitlinker executable followed by the desired command and options:

gitlinker command [options]

Editor Integration

Kakoune

Add this to your kakrc:

evaluate-commands %sh{
  gitlinker init kakoune
}

Then use:

  • :gitlinker - Copy permalink to clipboard
  • :gitlinker-open - Open permalink in browser

Neovim

Add the Lua plugin to your config:

-- Load gitlinker.cr plugin dynamically
_G.gitlinker = loadstring(vim.fn.system("gitlinker init neovim"))()
if _G.gitlinker then
  _G.gitlinker.setup()
end

-- Optional: Add keybindings
vim.keymap.set({ "n", "v" }, "<leader>gy", function() _G.gitlinker.copy() end, { desc = "Copy git permalink" })
vim.keymap.set({ "n", "v" }, "<leader>go", function() _G.gitlinker.open() end, { desc = "Open git permalink" })

Or with which-key:

require("which-key").add({
  { "<leader>gy", function() _G.gitlinker.copy() end, desc = "Copy Git Permalink", mode = { "n", "v", "x" } },
  { "<leader>go", function() _G.gitlinker.open() end, desc = "Open Git Permalink", mode = { "n", "v", "x" } },
})

Then use:

  • :Gitlinker - Copy permalink to clipboard
  • :GitlinkerOpen - Open permalink in browser
  • Or use the configured keymaps in normal/visual mode

Commands

  • run: Run gitlinker to generate URLs for specific lines of code.
  • init: Print initialization configurations.

Options

  • -v, --version: Show the version of Gitlinker.
  • -h, --help: Show the help information.
  • -f FILE, --file=FILE: Specify the path to the file for which you want to generate the URL.
  • -s LINE, --start-line=LINE: Specify the start line number.
  • -e LINE, --end-line=LINE: Specify the end line number (optional).

Examples

To generate a URL for a specific file and line number:

gitlinker run -f path/to/file.ext -s 10

To generate a URL for a specific file and line range:

gitlinker run -f path/to/file.ext -s 10 -e 20

To print editor integration code:

gitlinker init kakoune  # For Kakoune
gitlinker init neovim   # For Neovim

Configuration

Gitlinker uses a set of predefined routes to generate URLs for different Git hosting platforms. The routes are defined in the DEFAULT_ROUTERS constant in the Gitlinker::Configs module.

You can customize the routes by modifying the DEFAULT_ROUTERS constant to add, remove, or update the routes for different platforms.

Contributing

If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the Gitlinker repository.

License

Gitlinker is open-source software licensed under the MIT License.

About

Portable file permalink generator written in Crystal language. Working with Kakoune and neovim out of the box.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载