Skip to content

Instantly share code, notes, and snippets.

@shmup
Last active September 8, 2021 01:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shmup/db671132f0f9882187b28a677fa8df72 to your computer and use it in GitHub Desktop.
Save shmup/db671132f0f9882187b28a677fa8df72 to your computer and use it in GitHub Desktop.
nonymous-ix.vim uses .netrc for auth, and fucks with ix.io
" nonymous-ix.vim uses .netrc for auth, and fucks with ix.io
" insert :IX [optional visual selection] - copies url to system clipboard
" replace :RX <URL> [optional visual selection]
" delete :DX <URL>
if has('win64') || has('win32') || has('win16')
let s:env = 'WINDOWS'
else
let s:env = toupper(substitute(system('uname'), '\n', '', ''))
endif
" linux requires curl and xclip
if s:env =~ 'LINUX' && executable('xclip')
command! -range=% IX <line1>,<line2>w !curl -n -F 'f:1=<-' ix.io | tr -d '\n' | tee >(xclip -i -selection clipboard)
command! -nargs=1 -range=% RX <line1>,<line2>w !curl -n -X PUT -F 'f:1=<-' <args> | tr -d '\n' | tee >(xclip -i -selection clipboard)
command! -nargs=1 -range=% DX w !curl -n -X DELETE <args>
endif
" macos requires curl
if s:env =~ 'DARWIN'
command! -range=% IX <line1>,<line2>w !curl -n -F 'f:1=<-' ix.io | tr -d '\n' | tee >(pbcopy)
command! -nargs=1 -range=% RX <line1>,<line2>w !curl -n -X PUT -F 'f:1=<-' <args> | tr -d '\n' | tee >(pbcopy)
command! -nargs=1 -range=% DX w !curl -n -X DELETE <args>
endif
@shmup
Copy link
Author

shmup commented Apr 15, 2020

Because ix.io returns an existing ID if you try to -X PUT existing content, I decided I want to put the :RX <url> response on the clipboard, but still let it output visually in vim so you can visually read/click the URL.

Using tee >() does this for me, but unsure if it's the best way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment