trevorhauter / gitportal.nvim

Easily generate or ingest shareable permalinks to get to the files you want. Fast.
MIT License
5 stars 0 forks source link
# gitportal.nvim #### Bridging the gap between your favorite git host and neovim. Git Portal

꩜ Use cases

You want to quickly share a file with a coworker

A coworker shares a file with you

Click for preview | Opening file in github | Opening file in neovim | | --- | ----------- | |

꩜ Installation

꩜ Configuration

gitportal.nvim comes with the following defaults.

If you wish to keep these defaults, no configuration is required. If you wish to customize them, you must pass a dictionary of the options you'd like to override to the setup method. An example can be seen in my setup below.

{
  -- When opening generating permalinks, whether to always include the current line in
  -- the URL, regardless of visual mode.
  always_include_current_line = false,

  -- When ingesting permalinks, should gitportal always switch to the specified
  -- branch or commit?
  -- Can be "always", "ask_first", or "never"
  switch_branch_or_commit_upon_ingestion = "always",
}

꩜ Basic setup

Here is a brief example of the available functions and how I have them set up in my personal config.

local gitportal = require("gitportal")

gitportal.setup({
  always_include_current_line = true
})

-- open_file_in_browser() in normal mode
-- Opens the current file in your browser on the correct branch/commit.
vim.keymap.set("n", "<leader>gp", function() gitportal.open_file_in_browser() end)

-- open_file_in_browser() in visual mode
-- This behaves the same but it also includes the selected line(s) in the permalink.
vim.keymap.set("v", "<leader>gp", function() gitportal.open_file_in_browser() end)

-- open_file_in_neovim()
-- Requests a github link, optionally switches to the branch/commit, and
-- opens the specified file in neovim. Line ranges, if included, are respected.
vim.keymap.set('n', '<leader>ig', function() gitportal.open_file_in_neovim() end) 

꩜ Supported git web hosts

NOTE: Support for additional hosts will be added after release. If you'd like to use this plugin with a different web host, please open an issue. I'll do my best to add it quickly.

꩜ Comparison against other popular git browsing plugins

Feature gitportal.nvim vim-fugitive vim-rhubarb gitlinker.nvim
Open current file in browser, with optional line ranges :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark:
Open permalinks in neovim, with respect to line range, branch, or commit :white_check_mark: :x: :x: :x: