Skip to content

Instantly share code, notes, and snippets.

@blueyed
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blueyed/3445f580a1d91861b245 to your computer and use it in GitHub Desktop.
Save blueyed/3445f580a1d91861b245 to your computer and use it in GitHub Desktop.
" Paste using [gist-paste](https://github.com/defunkt/gist).
command! -range=% -nargs=* Gistpaste call MyGistpaste(<line1>, <line2>, <f-args>)
fun! MyGistpaste(line1, line2, ...) abort
" let args = ['-t', &ft] " overrides -f?!
let args = []
" Autoset -f, if it's not given.
if index(a:000, '-f') == -1
let fname = fnamemodify(expand('%'), ':t')
let ext = fnamemodify(fname, ':e')
if !len(ext)
let fname .= '.'.&ft
endif
let args += ['-f', fname]
endif
" Escape args.
for a in a:000 | let args += [shellescape(a)] | endfor
" let cmd = ':'.a:line1.','.a:line2.'w !gist-paste '.join(args, ' ')
let output = systemlist('gist-paste '.join(args, ' '), getline(a:line1, a:line2))
if len(output) == 1
" Just a single line: the gist URL, use 'echom'.
echom output[0]
else
" Multiple lines, e.g. from 'Gistpaste -h', use 'echo'.
for l in output
echo l
endfor
endif
endfun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment