Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions autoload/clipper/private.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,44 @@ endfunction
function! clipper#private#clip() abort
if exists('s:invocation') && s:invocation != ''
call system(s:invocation, @0)
elseif executable('nc') == 1
elseif clipper#private#executable() != ''
let l:executable = clipper#private#executable()
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)
" nc
call system(l:executable . ' ' . l:address . ' ' . l:port, @0)
else
call system('nc -U ' . l:address, @0)
" nc -U
call system(l:executable . ' -U ' . l:address, @0)
endif
else
echoerr 'Clipper: nc executable does not exist'
endif
endfunction

let s:executable=''

function! clipper#private#executable() abort
if s:executable == '' && executable('nc') == 1
" Try to figure out whether -N switch is supported and required.
" Examples:
" - Ubuntu, FreeBSD and similar:
" Supports and requires -N:
" "shutdown(2) the network socket after EOF on the input"
" http://manpages.ubuntu.com/manpages/bionic/man1/nc_openbsd.1.html
" https://www.freebsd.org/cgi/man.cgi?nc
" - Darwin:
" Supports but does not require -N; it does something else:
" "Number of probes to send before generating a write timeout event"
" - CentOS etc:
" Does not support or need -N.
let l:help = system('nc -h')
if match(l:help, '\v\s-N\s.+shutdown>') != -1
let s:executable = 'nc -N'
else
let s:executable = 'nc'
endif
endif
return s:executable
endfunction