2022-09-27 02:23:14 +03:00
# openingh.nvim
2022-09-27 02:24:25 +03:00
Opens the current file or project page in GitHub.
2022-10-03 23:04:03 +03:00
2022-10-30 02:13:08 +03:00


2023-03-25 00:20:33 +03:00
[](https://github.com/Almo7aya/openingh.nvim/actions/workflows/lint.yml)

2022-10-03 23:04:03 +03:00
2022-09-27 02:22:34 +03:00
- Features
2022-10-10 01:15:43 +03:00
- Supports macOS, Linux, Windows and WSL
2022-09-27 03:36:44 +03:00
- Works with detached HEAD and supports checked out branches or forks
2022-10-10 01:15:43 +03:00
- 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
2022-09-27 03:32:08 +03:00
- Demo
2022-09-27 03:29:50 +03:00

2022-09-27 02:22:34 +03:00
## Requirements
- Neovim 0.7.2+
## 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()
use "almo7aya/openingh.nvim"
end)
2022-09-27 02:22:34 +03:00
```
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`
2022-09-27 02:22:34 +03:00
- Opens the project's git repository page in GitHub.
2022-09-26 02:16:54 +03:00
- `:OpenInGHFile`
2023-05-26 22:31:02 +03:00
- Opens the current file page in GitHub. This command supports ranges.
- `:OpenInGHFileLines`
- Opens the current file page in GitHub. This command supports ranges.
2022-09-27 02:22:34 +03:00
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
2022-09-27 02:22:34 +03:00
- [x] Support the current file cursor position
2023-03-22 13:41:29 -04:00
- [x] Support visual mode to open a file in range selection
2022-10-10 01:15:43 +03:00
- [x] Support other version control websites
2022-09-25 23:30:27 +03:00
2022-09-27 02:30:10 +03:00
## Contribution
2022-10-10 01:15:43 +03: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 )
2022-09-25 23:30:27 +03:00