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

vim-clipper assumes bsd netcat #2

Closed
bradwood opened this issue Dec 18, 2018 · 14 comments
Closed

vim-clipper assumes bsd netcat #2

bradwood opened this issue Dec 18, 2018 · 14 comments

Comments

@bradwood
Copy link

bradwood commented Dec 18, 2018

@wincent
Further to this wincent/clipper#19 I have indeed verified that bsd netcat is assumed to be installed.

Would it be too much to ask for socat support?

@bradwood
Copy link
Author

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
Copy link
Owner

wincent commented Dec 18, 2018

@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.

@bradwood
Copy link
Author

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
Copy link
Owner

wincent commented Dec 18, 2018

This works, although it's fugly

You could be quoting the wikipedia Vimscript page!

@bradwood
Copy link
Author

@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 🍺

@bradwood bradwood changed the title vim-clipper assumes gnu netcat vim-clipper assumes bsd netcat Dec 20, 2018
@xiruizhao
Copy link

xiruizhao commented Jun 19, 2020

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
Copy link
Owner

wincent commented Jun 19, 2020

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
Copy link

xiruizhao commented Jun 19, 2020

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
Copy link
Owner

wincent commented Jun 19, 2020

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
Copy link

xiruizhao commented Jun 19, 2020

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
Copy link

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
Copy link
Owner

wincent commented Jun 19, 2020

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
Copy link
Author

Make that 21 ;)

@wincent
Copy link
Owner

wincent commented Jun 19, 2020

So I took a stab at autodetection: #3

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

3 participants