ruifm / gitlinker.nvim

A lua neovim plugin to generate shareable file permalinks (with line ranges) for several git web frontend hosts. Inspired by tpope/vim-fugitive's :GBrowse
GNU General Public License v3.0
538 stars 45 forks source link

Support copying via OSC #47

Closed j-hui closed 2 years ago

j-hui commented 2 years ago

Is your feature request related to a problem? Please describe. Yanking to the system clipboard only works if the Neovim instance is running on your host machine; it doesn't work if it's running inside an SSH session, for example.

Describe the solution you'd like Most popular terminal emulator seem to support the ANSI OSC52 sequence, an escape sequence that tells the terminal emulator to copy some text to the system clipboard.

Something like this is already implemented using ojroques/vim-oscyank.

It would be great if there were a gitlinker action that could do the same.

Describe alternatives you've considered

Perhaps this suggestion is simply out of the scope of this plugin (in which case this issue needn't be kept open except for reference).

In any case, the following action_callback makes use of vim-oscyank, and may be of interest to others:

require'gitlinker'.setup{                               
  opts = {                                              
    action_callback = function(url)                     
      vim.api.nvim_command('let @" = \'' .. url .. '\'')
      vim.fn.OSCYankString(url)                         
    end,                                                
  },                                                    
}                                                       

I also add the url to vim's unnamed register because I'm used to it being in sync with the system clipboard, but that's entirely optional.

ruifm commented 2 years ago

I did not know about OSC but sounds very interesting and useful for my ssh remote sessions.

Supporting OSC out-of-the-box is really out of scope for this plugin unless they include it in neovim core. Because of that, its support relies on an external plugin which makes that action_callback (although useful) not suited to be the default.

However, I would accept a PR that either:

j-hui commented 2 years ago

Totally understand about it being out of scope; just having action_callback gives users everything they need to make OSC yank work (like I did). The configuration isn't even that complicated.

I'll make a PR sometime soon.

ruifm commented 2 years ago

Closed by https://github.com/ruifm/gitlinker.nvim/pull/49