Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's possible to copy the permalink directly? #24

Open
guilhermeprokisch opened this issue Oct 13, 2023 · 5 comments
Open

It's possible to copy the permalink directly? #24

guilhermeprokisch opened this issue Oct 13, 2023 · 5 comments

Comments

@guilhermeprokisch
Copy link

guilhermeprokisch commented Oct 13, 2023

I wondered if copying the permalink directly from the plugin is too complicated since the OpenInGHLines already highlights the correct lines.

@guilhermeprokisch guilhermeprokisch changed the title It's possible to copy the permalink direclty? It's possible to copy the permalink directly? Oct 13, 2023
@knpwrs
Copy link

knpwrs commented Jan 30, 2024

I think this should be possible to implement using the following lua code:

vim.fn.setreg('+', url)

@knpwrs
Copy link

knpwrs commented Jan 30, 2024

Actually, reading the README, this appears to already be implemented:

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.

@samuelhwilliams
Copy link

The readme does seem to suggest it should work, but when I do that, it still opens the link in the browser?

@rollf
Copy link

rollf commented Jun 17, 2024

OpenInGHFileLines+ doesn't work for me neither. A GitHub search suggests that it should work though 🤷 .

@rperryng
Copy link

rperryng commented Jul 7, 2024

It isn't mentioned in the README.md but in the help doc the author writes:

To copy the URL into a register set
vim.g.openingh_copy_to_register = true
(helpdoc)

This needs to be set before the plugin is loaded, since it's used when the plugins' User Commands are being created (code), not when the user command is called (this is just how the nvim_create_user_command API works, although I feel like the plugin should just always set the reg option to true, since it can be opted out of when being called by just not passing a register[1]*)

anyways, with that said, here's a working config you can use:

return {
  'Almo7aya/openingh.nvim',
  init = function()
    vim.g.openingh_copy_to_register = true
  end,
  config = function()
    -- ...

    vim.keymap.set('v', '<space>ygh', ':OpenInGHFileLines+<cr>', {
      silent = true,
      noremap = true,
      desc = 'Yank GitHub link to system clipboard',
    })
  end,
}

If you want to copy a permalink, you need to specify both the bang (!, to prioritize the commit sha, as described in the readme) and then pass the register as the first argument, i.e. :OpenInGHFileLines! + (note the space between ! and +)

e.g.

vim.keymap.set('v', '<space>ygh', ':OpenInGHFileLines! +<cr>', {
  silent = true,
  noremap = true,
  desc = 'Yank GitHub permalink to system clipboard',
})

[1]*: Actually this changes how the command interprets the first argument, and so if you frequently pass an explicit branch name to the commands then you might not want this to be set to true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants