From f221b7c366a15d1d8dd8a9103dbf410ce0a57b15 Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Sat, 23 Apr 2016 02:02:46 -0500 Subject: [PATCH] add g:sprunge_providers option, attempt to fix issue #13 --- autoload/sprunge.vim | 52 ++++++++++++++++++++++++++++++++++---------- doc/sprunge.txt | 23 ++++++++++++++++++-- plugin/sprunge.vim | 11 ++++------ 3 files changed, 66 insertions(+), 20 deletions(-) diff --git a/autoload/sprunge.vim b/autoload/sprunge.vim index 53b44cf..c5d744f 100644 --- a/autoload/sprunge.vim +++ b/autoload/sprunge.vim @@ -6,10 +6,10 @@ " ============================================================================ function! sprunge#CopyToClipboard(clip) "{{{ - if g:sprunge_clipboard == 'vim' || g:sprunge_clipboard == 'all' + if g:sprunge_clipboard ==? 'vim' || g:sprunge_clipboard ==? 'all' call setreg('"', a:clip) endif - if g:sprunge_clipboard == 'external' || g:sprunge_clipboard == 'all' + if g:sprunge_clipboard ==? 'external' || g:sprunge_clipboard ==? 'all' if executable('xclip') call system('printf "' . a:clip . '"' . ' | ' . \ 'xclip -selection clipboard; xclip -o -selection clipboard') @@ -28,7 +28,7 @@ function! sprunge#CopyToClipboard(clip) "{{{ endif endfunction -function! sprunge#FlushLeft(line1, line2) "{{{1 +function! sprunge#FlushLeft(line1, line2) "{{{ let l:current_line = a:line1 let l:min_white_spaces = 9999 while l:current_line <= a:line2 @@ -49,18 +49,48 @@ function! sprunge#FlushLeft(line1, line2) "{{{1 return l:buffer endfunction -function! sprunge#OpenBrowser(url) "{{{1 +function! sprunge#OpenBrowser(url) "{{{ + if a:url =~# '//sprunge.us/' + let l:url = a:url . '?' . &filetype + elseif a:url =~# '//ix.io/' + let l:url = a:url . '/' . &filetype + else + let l:url = a:url + endif if has("win32") - exe "!start cmd /cstart /b ".a:url."" + exe "!start cmd /cstart /b ".l:url."" elseif $DISPLAY !~ '^\w' - exe "silent !sensible-browser \"".a:url."\"" + exe "silent !sensible-browser \"".l:url."\"" else - exe "silent !sensible-browser -T \"".a:url."\"" + exe "silent !sensible-browser -T \"".l:url."\"" endif redraw! endfunction -function! sprunge#Post(line1, line2) "{{{ +function! sprunge#Post(buffer, ...) "{{{ + if a:0 > 0 + if a:1 ==? "sprunge" + return system('curl -s -F "sprunge=<-" http://sprunge.us', a:buffer) + elseif a:1 ==? "ix" + return system('curl -s -F "f:1=<-" http://ix.io', a:buffer) + endif + else + if !exists('g:sprunge_cmd') + for l:provider in split(g:sprunge_providers, ',') + let l:url = sprunge#Post(a:buffer, l:provider) + if l:url =~# '^http.*' | break | endif + endfor + if !exists('l:url') + let l:url = system('curl -s -F "sprunge=<-" http://sprunge.us', a:buffer) + endif + else + let l:url = system(g:sprunge_cmd, a:buffer) + endif + endif + return l:url[0:-2] +endfunction + +function! sprunge#Sprunge(line1, line2) "{{{ if !exists('g:sprunge_cmd') && !executable('curl') echoerr "Sprunge: requires 'curl'" return @@ -70,8 +100,8 @@ function! sprunge#Post(line1, line2) "{{{ else let buffer = sprunge#FlushLeft(a:line1, a:line2) endif - redraw | echon 'Posting to sprunge ... ' - let l:url = system(g:sprunge_cmd, buffer)[0:-2] + redraw | echon 'Posting ... ' + let l:url = sprunge#Post(buffer) if empty(l:url) let l:url = system("curl -s http://google.com") if empty(l:url) @@ -81,7 +111,7 @@ function! sprunge#Post(line1, line2) "{{{ endif else call sprunge#CopyToClipboard(l:url) - if g:sprunge_open_browser | call sprunge#OpenBrowser(l:url . '?' . &filetype) | endif + if g:sprunge_open_browser | call sprunge#OpenBrowser(l:url) | endif redraw | echomsg 'Done: ' . l:url endif endfunction diff --git a/doc/sprunge.txt b/doc/sprunge.txt index e832ab3..76c1575 100644 --- a/doc/sprunge.txt +++ b/doc/sprunge.txt @@ -57,6 +57,14 @@ g:sprunge_cmd *SprungeConfig-cmd* let g:sprunge_cmd = 'curl -s -F "sprunge=<-" http://sprunge.us' < +g:sprunge_providers *SprungeConfig-providers* + Default providers + + Use this option to customize the order in which the default providers are + called. > + let g:sprunge_providers = 'sprunge,ix' +< + g:sprunge_clipboard *SprungeConfig-clipboard* Default clipboard @@ -76,23 +84,29 @@ g:sprunge_clipboard *SprungeConfig-clipboard* g:sprunge_clipboard_cmd *SprungeConfig-clipboard-cmd* User defined clipboard - Use this option to configure third party clipboard application. > + Use this option to configure a third party clipboard application. > let g:sprunge_clipboard_cmd = 'clipboard_app --option' < g:sprunge_open_browser *SprungeConfig-open-browser* + Browser trigger + Use this option to open the sprunge link automatically in your default browser. Disabled by default. > let g:sprunge_open_browser = 0 < g:sprunge_flush_left *SprungeConfig-flush-left* - Use this option to aligned along the left margin before pasting. Disabled + Left align + + Use this option to align along the left margin before pasting. Disabled by default. > let g:sprunge_flush_left = 0 < g:sprunge_map *SprungeConfig-map* + Default mapping + Use this option to configure the default mapping > let g:sprunge_map = 's' < @@ -125,6 +139,11 @@ GitHub: http://github.com/chilicuil/sprunge-vim/ ============================================================================== CHANGELOG *SprungeChangelog* +v0.0.6 + * Add the option to align to the left before pasting, enabled by + g:sprunge_flush_left + * Add the notion of multiple providers, enabled by g:sprunge_providers + * Add new provider http://ix.io v0.0.5 * Add xsel to the default clipboard app list * Add g:sprunge_cmd diff --git a/plugin/sprunge.vim b/plugin/sprunge.vim index b3c1136..4f0ed0b 100644 --- a/plugin/sprunge.vim +++ b/plugin/sprunge.vim @@ -17,10 +17,6 @@ if v:version < '700' finish endif -if executable('curl') && !exists('g:sprunge_cmd') - let g:sprunge_cmd = 'curl -s -F "sprunge=<-" http://sprunge.us' -endif - " Default configuration {{{1 if exists('g:sprunge_clipboard') let g:sprunge_clipboard = g:sprunge_clipboard =~? 'none\|vim\|external\|all' ? tolower(g:sprunge_clipboard) : 'all' @@ -28,11 +24,12 @@ else let g:sprunge_clipboard = 'all' endif -if !exists('g:sprunge_open_browser') | let g:sprunge_open_browser = 0 | endif -if !exists('g:sprunge_map') | let g:sprunge_map = 's' | endif +if !exists('g:sprunge_providers') | let g:sprunge_providers = 'sprunge,ix' | endif +if !exists('g:sprunge_open_browser') | let g:sprunge_open_browser = 0 | endif +if !exists('g:sprunge_map') | let g:sprunge_map = 's' | endif " Commands & Mappings {{{1 -command! -nargs=0 -range=% Sprunge call sprunge#Post(,) +command! -nargs=0 -range=% Sprunge call sprunge#Sprunge(,) if !hasmapto('Sprunge') try