Skip to content

Commit

Permalink
add g:sprunge_providers option, attempt to fix issue #13
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-lopez committed Apr 23, 2016
1 parent 78b610f commit f221b7c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 20 deletions.
52 changes: 41 additions & 11 deletions autoload/sprunge.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
23 changes: 21 additions & 2 deletions doc/sprunge.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = '<Leader>s'
<
Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions plugin/sprunge.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@ 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'
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 = '<Leader>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 = '<Leader>s' | endif

" Commands & Mappings {{{1
command! -nargs=0 -range=% Sprunge call sprunge#Post(<line1>,<line2>)
command! -nargs=0 -range=% Sprunge call sprunge#Sprunge(<line1>,<line2>)

if !hasmapto('<Plug>Sprunge')
try
Expand Down

0 comments on commit f221b7c

Please sign in to comment.