Open the current file (or lines) in remote git repository.
Find a file
2023-10-31 14:36:49 +03:00
.github/workflows made use of GitHub-styled usage 2023-02-03 14:31:56 -06:00
doc changed the behavior to make the plugin follow the current repository of the current buffer 2022-09-28 12:18:45 -04:00
gifs chore: add gif demo to README.md 2022-09-27 03:29:50 +03:00
lua/openingh feat: Support alternate SSH usernames i.e. non-standard GitHub Enterprise setups 2023-10-25 23:52:12 -07:00
plugin Control priority by bang 2023-09-23 10:26:40 +09:00
tests Added a few tests for encode_uri_component 2023-06-02 19:01:59 +09:00
.gitignore Add .gitignore file 2023-08-26 21:30:28 +02:00
.luacheckrc chore: add actions to format and lint the code 2022-09-26 23:28:51 +03:00
.pre-commit-config.yaml chore: add pre-commit config 2022-09-26 23:46:12 +03:00
LICENSE chore: add LICENSE file 2022-09-27 01:43:30 +03:00
Makefile chore: add testing for user commands 2022-10-30 02:03:40 +03:00
README.md Added description about priority and how to control it 2023-09-23 11:10:49 +09:00
stylua.toml chore: initial commit 2022-09-25 23:30:27 +03:00

openingh.nvim

Opens the current file or project page in GitHub.

Lua GitHub release (latest by date) lint with luacheck GitHub Workflow Status

  • Features

    • Supports macOS, Linux, Windows and WSL
    • Works with detached HEAD and supports checked out branches or forks
    • Automatically selects the correct line number on the file page
    • Supports GitHub, GitHub Enterprise, GitLab, and Bitbucket
  • Demo

Requirements

  • Neovim 0.7.2+

Installation

Example with Packer

wbthomason/packer.nvim

-- init.lua
require("packer").startup(function()
  use "almo7aya/openingh.nvim"
end)

Commands

  • :OpenInGHRepo

    • Opens the project's git repository page in GitHub.
  • :OpenInGHFile

    • Opens the current file page in GitHub. This command supports ranges.
  • :OpenInGHFileLines

    • Opens the current file page in GitHub. This command supports ranges.

Registers

All of the commands above optionally take a register, e.g. :OpenInGHFileLines+. In this case, the URL will not be opened in the browser, but put into the register given. This is especially useful if you're running neovim on a remote machine, but want to open the URL locally.

Priority

At first, this plugin try to identify the page url based on the current branch you are working in, and if it fails then switches its base to commit.

This behavior can be inverted via bang !, e.g. :OpenInGHFile!.

Since commit based url tends to have long durablity compared to branch based one, it can be useful in some situation. It won't be affected by subsequent commits, branch deletion after merge, and so on.

Usage

You can call the commands directly or define mappings them:

-- for repository page
vim.api.nvim_set_keymap("n", "<Leader>gr", ":OpenInGHRepo <CR>", { silent = true, noremap = true })

-- for current file page
vim.api.nvim_set_keymap("n", "<Leader>gf", ":OpenInGHFile <CR>", { silent = true, noremap = true })
vim.api.nvim_set_keymap("v", "<Leader>gf", ":OpenInGHFileLines <CR>", { silent = true, noremap = true })

TODO

  • Support the current file cursor position
  • Support visual mode to open a file in range selection
  • Support other version control websites

Contribution

Feel free to open an issue or a pull request if you have any suggestions or improvements

License

MIT