Skip to content

Commit

Permalink
Merge pull request #4 from simmel/add_private_pastie
Browse files Browse the repository at this point in the history
Add private pastie
  • Loading branch information
tpope committed May 15, 2015
2 parents 0b70a88 + ac5a7f1 commit 7379c38
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
3 changes: 3 additions & 0 deletions doc/pastie.txt
Expand Up @@ -61,4 +61,7 @@ and in previous versions, :match (use ":match none" to disable).
The URL sometimes disappears with the bang (:Pastie!) variant. You can still
retrieve it from the clipboard.

If you want to create a private pastie you'll need to update `pastie_private`
$ let pastie_private = 1

vim:tw=78:et:ft=help:norl:
53 changes: 30 additions & 23 deletions plugin/pastie.vim
Expand Up @@ -8,16 +8,20 @@ if exists("g:loaded_pastie") || &cp
endif
let g:loaded_pastie = 1

if !exists("g:pastie_private")
let g:pastie_private = 0
endif

augroup pastie
autocmd!
autocmd BufReadPre http://pastie.org/*[0-9]?key=* call s:extractcookies(expand("<amatch>"))
autocmd BufReadPost http://pastie.org/*[0-9]?key=* call s:PastieSwapout(expand("<amatch>"))
autocmd BufReadPost http://pastie.org/*[0-9] call s:PastieSwapout(expand("<amatch>"))
autocmd BufReadPost http://pastie.org/pastes/*[0-9]/download call s:PastieRead(expand("<amatch>"))
autocmd BufReadPost http://pastie.org/*[0-9].* call s:PastieRead(expand("<amatch>"))
autocmd BufWriteCmd http://pastie.org/pastes/*[0-9]/download call s:PastieWrite(expand("<amatch>"))
autocmd BufWriteCmd http://pastie.org/*[0-9].* call s:PastieWrite(expand("<amatch>"))
autocmd BufWriteCmd http://pastie.org/pastes/ call s:PastieWrite(expand("<amatch>"))
autocmd BufReadPre http://pastie.org/*[0-9]?key=* call s:extractcookies(expand("<amatch>"))
autocmd BufReadPost http://pastie.org/*[0-9]?key=* call s:PastieSwapout(expand("<amatch>"))
autocmd BufReadPost http://pastie.org/*[0-9] call s:PastieSwapout(expand("<amatch>"))
autocmd BufReadPost http://pastie.org/pastes/*[0-9]/download call s:PastieRead(expand("<amatch>"))
autocmd BufReadPost http://pastie.org/*[0-9].* call s:PastieRead(expand("<amatch>"))
autocmd BufWriteCmd http://pastie.org/pastes/*[0-9a-f]/download call s:PastieWrite(expand("<amatch>"), g:pastie_private)
autocmd BufWriteCmd http://pastie.org/*[0-9a-f].* call s:PastieWrite(expand("<amatch>"), g:pastie_private)
autocmd BufWriteCmd http://pastie.org/pastes/ call s:PastieWrite(expand("<amatch>"), g:pastie_private)

autocmd BufReadPre http://pastie.caboo.se/*[0-9]?key=* call s:extractcookies(expand("<amatch>"))
autocmd BufReadPost http://pastie.caboo.se/*[0-9]?key=* call s:PastieSwapout(expand("<amatch>"))
Expand Down Expand Up @@ -285,7 +289,7 @@ function! s:afterload()
syn match pastieNonText '^!!' containedin=rubyString
endfunction

function! s:PastieWrite(file)
function! s:PastieWrite(file, ...)
let parser = s:parser(&ft)
let tmp = tempname()
let num = matchstr(a:file,'/\@<!/\zs\d\+')
Expand All @@ -308,27 +312,30 @@ function! s:PastieWrite(file)
endif
silent exe "write ".tmp
let result = ""
let rubycmd = 'obj = Net::HTTP.start(%{'.s:domain.'}){|h|h.post(%{'.url.'}, %q{'.method.'paste[parser]='.parser.pdn.'&paste[authorization]=burger&paste[key]=&paste[body]=} + File.read(%q{'.tmp.'}).gsub(/^(.*?) *#\!\! *#{36.chr}/,%{!\!}+92.chr+%{1}).gsub(/[^a-zA-Z0-9_.-]/n) {|s| %{%%%02x} % (s.ord rescue s[0])},{%{Cookie} => %{'.s:cookies().'}})}; print obj[%{Location}].to_s+%{ }+obj[%{Set-Cookie}].to_s'

let private = "&paste[restricted]=".g:pastie_private

let rubycmd = 'obj = Net::HTTP.start(%{'.s:domain.'}){|h|h.post(%{'.url.'}, %q{'.method.'paste[parser]='.parser.pdn.'&paste[authorization]=burger'.private.'&paste[key]=&paste[body]=} + File.read(%q{'.tmp.'}).gsub(/^(.*?) *#\!\! *#{36.chr}/,%{!\!}+92.chr+%{1}).gsub(/[^a-zA-Z0-9_.-]/n) {|s| %{%%%02x} % (s.ord rescue s[0])},{%{Cookie} => %{'.s:cookies().'}})}; print obj[%{Location}].to_s+%{ }+obj[%{Set-Cookie}].to_s'
let result = system('ruby -rnet/http -e "'.rubycmd.'"')
let redirect = matchstr(result,'^[^ ]*')
let cookies = matchstr(result,'^[^ ]* \zs.*')
call s:extractcookiesfromheader(cookies)
call delete(tmp)
if redirect =~ '^\w\+://'
set nomodified
let b:pastie_update = 1
"silent! let @+ = result
silent! let @* = redirect
silent exe "file ".redirect.s:dl_suffix
" TODO: make a proper status message
echo '"'.redirect.'" written'
silent exe "doautocmd BufWritePost ".redirect.s:dl_suffix
set nomodified
let b:pastie_update = 1
"silent! let @+ = result
silent! let @* = redirect
silent exe "file ".redirect.s:dl_suffix
" TODO: make a proper status message
echo '"'.redirect.'" written'
silent exe "doautocmd BufWritePost ".redirect.s:dl_suffix
else
if redirect == ''
let redirect = "Could not post to ".url
endif
let redirect = substitute(redirect,'^-e:1:\s*','','')
call s:error(redirect)
if redirect == ''
let redirect = "Could not post to ".url
endif
let redirect = substitute(redirect,'^-e:1:\s*','','')
call s:error(redirect)
endif
endfunction

Expand Down

0 comments on commit 7379c38

Please sign in to comment.