Last active
August 29, 2015 14:14
-
-
Save blueyed/3445f580a1d91861b245 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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