2022-09-27 02:23:14 +03:00
|
|
|
# openingh.nvim
|
2022-10-03 23:04:03 +03:00
|
|
|
|
2024-10-22 10:16:45 +01:00
|
|
|
Opens the current file or project page in the web interface of the remote.
|
2022-10-03 23:04:03 +03:00
|
|
|
|
2024-10-22 10:16:45 +01:00
|
|
|

|
2022-10-03 23:04:03 +03:00
|
|
|
|
2024-10-22 10:16:45 +01:00
|
|
|
- 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
|
2022-09-25 23:30:27 +03:00
|
|
|
|
2024-10-22 10:16:45 +01:00
|
|
|
- Demo
|
2022-09-27 03:32:08 +03:00
|
|
|
|
2022-09-27 03:29:50 +03:00
|
|
|

|
|
|
|
|
|
2022-09-27 02:22:34 +03:00
|
|
|
## Requirements
|
|
|
|
|
|
2024-10-22 10:16:45 +01:00
|
|
|
- Neovim 0.7.2+
|
2022-09-27 02:22:34 +03:00
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
2022-09-27 03:01:13 +03:00
|
|
|
#### Example with Packer
|
|
|
|
|
|
|
|
|
|
[wbthomason/packer.nvim](https://github.com/wbthomason/packer.nvim)
|
2022-09-27 02:22:34 +03:00
|
|
|
|
|
|
|
|
```lua
|
2022-09-27 03:40:51 +03:00
|
|
|
-- init.lua
|
|
|
|
|
require("packer").startup(function()
|
2024-10-22 10:16:45 +01:00
|
|
|
use "https://gitea.gwairfelin.com/max/openingh.nvim"
|
2022-09-27 03:40:51 +03:00
|
|
|
end)
|
2022-09-27 02:22:34 +03:00
|
|
|
```
|
2022-09-25 23:30:27 +03:00
|
|
|
|
2024-10-22 10:29:08 +01:00
|
|
|
#### Example with lazyvim
|
|
|
|
|
|
|
|
|
|
```lua
|
|
|
|
|
return {
|
|
|
|
|
{
|
|
|
|
|
"https://gitea.gwairfelin.com/max/openingh.nvim",
|
|
|
|
|
keys = {
|
|
|
|
|
{
|
|
|
|
|
"<leader>gB",
|
|
|
|
|
"<cmd>OpenInGHFile!<cr>",
|
|
|
|
|
desc = "Open this file in the git remote",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"<leader>gB",
|
|
|
|
|
"<cmd>'<,'>OpenInGHFileLines!<cr>",
|
|
|
|
|
desc = "Open these lines in the git remote",
|
|
|
|
|
mode = "v",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2022-09-25 23:30:27 +03:00
|
|
|
## Commands
|
2022-09-27 02:22:34 +03:00
|
|
|
|
2022-09-26 02:16:54 +03:00
|
|
|
- `:OpenInGHRepo`
|
2024-10-22 10:16:45 +01:00
|
|
|
- Opens the project's git repository page in the remote.
|
2022-09-26 02:16:54 +03:00
|
|
|
|
|
|
|
|
- `:OpenInGHFile`
|
2024-10-22 10:16:45 +01:00
|
|
|
- Opens the current file page in the remote.
|
2023-05-26 22:31:02 +03:00
|
|
|
|
|
|
|
|
- `:OpenInGHFileLines`
|
2024-10-22 10:16:45 +01:00
|
|
|
- Opens the current file page in the remote, with the lines highlighted. This
|
|
|
|
|
command supports ranges.
|
2023-08-27 11:18:00 +02:00
|
|
|
|
|
|
|
|
## 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.
|
|
|
|
|
|
2023-09-23 11:10:49 +09:00
|
|
|
## 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.
|
|
|
|
|
|
2022-09-27 02:22:34 +03:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
You can call the commands directly or define mappings them:
|
|
|
|
|
|
|
|
|
|
```lua
|
|
|
|
|
-- for repository page
|
2023-03-23 09:30:33 -04:00
|
|
|
vim.api.nvim_set_keymap("n", "<Leader>gr", ":OpenInGHRepo <CR>", { silent = true, noremap = true })
|
2022-09-27 02:22:34 +03:00
|
|
|
|
|
|
|
|
-- for current file page
|
2023-03-23 09:30:33 -04:00
|
|
|
vim.api.nvim_set_keymap("n", "<Leader>gf", ":OpenInGHFile <CR>", { silent = true, noremap = true })
|
2023-05-26 22:31:02 +03:00
|
|
|
vim.api.nvim_set_keymap("v", "<Leader>gf", ":OpenInGHFileLines <CR>", { silent = true, noremap = true })
|
2022-09-27 02:22:34 +03:00
|
|
|
```
|
2022-09-25 23:30:27 +03:00
|
|
|
|
2022-09-27 02:22:34 +03:00
|
|
|
## TODO
|
2022-09-27 02:30:10 +03:00
|
|
|
|
2024-10-22 10:16:45 +01:00
|
|
|
- [x] Support the current file cursor position
|
|
|
|
|
- [x] Support visual mode to open a file in range selection
|
|
|
|
|
- [x] Support other version control websites
|
2022-09-25 23:30:27 +03:00
|
|
|
|
2022-09-27 02:30:10 +03:00
|
|
|
## Contribution
|
|
|
|
|
|
2024-10-22 10:16:45 +01:00
|
|
|
Feel free to open an issue or a pull request if you have any suggestions or improvements
|
2022-09-27 02:30:10 +03:00
|
|
|
|
2022-09-27 02:22:34 +03:00
|
|
|
## License
|
2022-09-27 02:30:10 +03:00
|
|
|
|
2022-09-27 02:22:34 +03:00
|
|
|
[MIT](./LICENSE)
|