wincent / vim-clipper

Clipper integration for Vim
BSD 2-Clause "Simplified" License
43 stars 5 forks source link

vim-clipper assumes bsd netcat #2

Closed bradwood closed 5 years ago

bradwood commented 5 years ago

@wincent Further to this https://github.com/wincent/clipper/issues/19 I have indeed verified that bsd netcat is assumed to be installed.

Would it be too much to ask for socat support?

bradwood commented 5 years ago

Here's my attempt... It's not working and my vimscript is sh*te...


function! clipper#private#clip() abort
  if executable('nc') == 1
    let l:address = get(g:, 'ClipperAddress', 'localhost')
    let l:port = +(get(g:, 'ClipperPort', 8377)) " Co-erce to number.
    if l:port
      call system('nc ' . l:address . ' ' . l:port, @0)
    else
      if executable('socat') == 1
        call system('socat - unix-client:' . l:address, @0)
      else
        call system('nc -U ' . l:address, @0)
      endif
    endif
  else
    echoerr 'Clipper: suitable executable does not exist'
  endif
endfunction

Is there a way to pipe the cut data in via vimscript?

wincent commented 5 years ago

@bradwood: Check out https://github.com/wincent/vim-clipper/commit/0200f2fbfb63189501c66cb723bf6a2984e1f91d and let me know what you think. Rather than play whack-a-mole and add more and more exceptions for specific environments, I prefer to just provide an escape hatch so that you can force exactly (and whatever) you want.

bradwood commented 5 years ago

Heh:

I just did this dirty hack as my logic on the one above was wrong... This works, although it's fugly...

function! clipper#private#clip() abort
  let l:address = get(g:, 'ClipperAddress', 'localhost')
  let l:port = +(get(g:, 'ClipperPort', 8377)) " Co-erce to number.

  if executable('nc') == 1
    if l:port
      call system('nc ' . l:address . ' ' . l:port, @0)
    else
      call system('nc -U ' . l:address, @0)
    endif
  else
    echoerr 'Clipper: nc executable does not exist'
  endif

  if executable('socat') == 1
    if l:port == 0
      call system('socat - unix-client:/' . l:address, @0)
    endif
  else
    echoerr 'Clipper: socat executable does not exist'
  endif
endfunction

Checking yours out now.

wincent commented 5 years ago

This works, although it's fugly

You could be quoting the wikipedia Vimscript page!

bradwood commented 5 years ago

@bradwood: Check out 0200f2f and let me know what you think. Rather than play whack-a-mole and add more and more exceptions for specific environments, I prefer to just provide an escape hatch so that you can force exactly (and whatever) you want.

Excellent. Thank you Greg... This works perfectly...

Let me also take this opportunity to thank you for all your vim content and code... I'm an avid subscriber to your channel which is excellent!

cheers :beer:

xiruizhao commented 4 years ago

macOS has always shipped their specific version of nc , however Ubuntu 18.04 LTS, Ubuntu 20.04 LTS, and FreeBSD 12.1 ship a version of nc that requires -N (I assume Debian is the same). CentOS 7 doesn't ship netcat or socat by default but can install an nmap-ncat that doesn't require -N. Could you add an exception for ubuntu so that I don't need to manage two vimrcs and this plugin works out of box?

wincent commented 4 years ago

You don't need two .vimrc files. Put an if/else inside and call clipper#set_invocation() accordingly. I don't think I can provide an out-of-the-box configuration that works for every platform out they, because I use a single platform myself and can't easily test other platforms.

If you can think of an improvement that would be generally applicable, always open to PRs.

xiruizhao commented 4 years ago

like this?

if system('uname') == 'Linux' " Ubuntu and FreeBSD
    call clipper#set_invocation('nc -N localhost 8377')
else 
    call clipper#set_invocation('nc localhost 8377')
endif
wincent commented 4 years ago

Yeah, something like that. But like I said, it can be hard to come up with something that works universally for every possible distro, so that's why I suggested starting without something in your .vimrc as opposed to trying to solve it automatically for everybody (the risk being that any change we make might improve things for some users and make them worse for others). That's why I added clipper#set_invocation() as a general-purpose escape hatch — I can't necessarily make it easy for everybody, but I can at least make it possible.

xiruizhao commented 4 years ago

But Ubuntu is so popular maybe make an exception? CentOS requires a hassle anyway since they don't even install netcat by default. Or put this Ubuntu bug more prominently (for example in https://github.com/wincent/clipper#linux-example-setup)? You mentioned this in https://github.com/wincent/clipper#fixing-delays-when-sending-data-to-clipper-via-nc, but I thought it wasn't relevant: it's not a delay, the nc process doesn't terminate on reading EOF and hangs indefinitely.

xiruizhao commented 4 years ago

I installed clipper several months ago and didn't figure out the cause of this bug until now LOL. Personally I think clipper is much better than other tmux/vim clipboard integration plugins because I can copy from remote machine's vim session, which isn't possible with them. Great work!

wincent commented 4 years ago

You mentioned this in https://github.com/wincent/clipper#fixing-delays-when-sending-data-to-clipper-via-nc

Yeah, but it came in via a third-party report. Like you say, it might not be discoverable enough.

Sigh... well this project has 20 stars, so maybe I shouldn't be too worried breaking things.

bradwood commented 4 years ago

Make that 21 ;)

wincent commented 4 years ago

So I took a stab at autodetection: https://github.com/wincent/vim-clipper/pull/3