From caa8a608303db243c12aff8586fbe41bdf2e562c Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Wed, 7 Oct 2009 03:37:07 +0000 Subject: [PATCH] updating vpaste --- 2html-et.patch | 33 ++++++++++++ index.cgi | 134 +++++++++++++++++++++++++++++++++++++------------ vpaste | 12 +++++ 3 files changed, 146 insertions(+), 33 deletions(-) create mode 100644 2html-et.patch create mode 100755 vpaste diff --git a/2html-et.patch b/2html-et.patch new file mode 100644 index 0000000..50d01b8 --- /dev/null +++ b/2html-et.patch @@ -0,0 +1,33 @@ +--- /usr/share/vim/vim72/syntax/2html.vim 2009-06-16 06:24:31.000000000 +0000 ++++ /tmp/2html.vim 2009-10-06 23:05:11.000000000 +0000 +@@ -192,7 +192,6 @@ + let s:old_report = &report + let s:old_search = @/ + set notitle noicon +-setlocal et + set report=1000000 + + " Split window to create a buffer with the HTML file. +@@ -393,12 +392,16 @@ + + " Expand tabs + let s:expandedtab = strpart(s:line, s:startcol - 1, s:col - s:startcol) +- let idx = stridx(s:expandedtab, "\t") +- while idx >= 0 +- let i = &ts - ((idx + s:startcol - 1) % &ts) +- let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', i), '') +- let idx = stridx(s:expandedtab, "\t") +- endwhile ++ if &et ++ let idx = stridx(s:expandedtab, "\t") ++ while idx >= 0 ++ let i = &ts - ((idx + s:startcol - 1) % &ts) ++ let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', i), '') ++ let idx = stridx(s:expandedtab, "\t") ++ endwhile ++ else ++ setlocal isprint+=9 ++ endif + + " Output the text with the same synID, with class set to {s:id_name} + let s:id = synIDtrans(s:id) diff --git a/index.cgi b/index.cgi index e8c14f1..a074f8a 100755 --- a/index.cgi +++ b/index.cgi @@ -14,35 +14,63 @@ # Remove url codings form stdin function urldecode { - sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e + sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g; s/[,&]/ /g' | xargs echo -e } # Extract an uploaded file from standard input # $1 is the boundary delimiter for the file function cut_file { awk " - /--$1/ {st=1}; - st==2 {print \$0}; - /$1--/ {st=0}; + /--$1/ {st=1}; + st==2 {print \$0}; + /$1--/ {st=0}; /^\\r$/ && st==1 {st=2}; " | head -c -2 # Remove trailing ^M's that come with CGI } +# Print out a generic header +function start_html { + echo "Content-Type: text/html; charset=UTF-8" + echo +} + +# Print out a generic header +function start_text { + echo "Content-Type: text/plain; charset=UTF-8" + echo +} + # Format a file for viewing function do_print { - [ -f "$1" ] && input="$1" || input="db/$1" - output="$(mktemp)" + if [ -f "$1" ]; then + input="$1" + elif [ -f "db/$1" ]; then + input="db/$1" + else + echo "Status: 404" + start_text + echo "File '$1' not found" + return + fi + modeline="$(echo $QUERY_STRING | urldecode)" - # I have some plugins in ~/.vim - # - # Run vimhi.sh in screen to trick it into thinking - # that it has a real terminal, not that we also have to - # set term=xterm-256color in vimrc - HOME=/home/andy \ - screen -D -m ./vimhi.sh "$input" "$output" "$modeline" - cat "$output" + if [ -z "$modeline" ]; then + start_text + cat "$input" + else + # I have some plugins in ~/.vim + # + # Run vimhi.sh in screen to trick it into thinking + # that it has a real terminal, not that we also have to + # set term=xterm-256color in vimrc + output="$(mktemp)" + HOME=/home/andy \ + screen -D -m ./vimhi.sh "$input" "$output" "$modeline" + start_html + cat "$output" + fi } @@ -51,29 +79,73 @@ function do_upload { output="$(mktemp db/XXXXX)" uri="$SCRIPT_URI$(basename "$output")" cut_file "$1" > "$output" + start_text echo "$uri" } # Default index page function do_help { +filetypes=$( + ls /usr/share/vim/vim{72,files}/syntax/ /home/andy/.vim/after/syntax/ | + sed -n 's/.vim$//p' | sort | uniq +) +uploads=$(ls -t db | head -n 5 | sed "s!^!$SCRIPT_URI!") + +start_html cat - < + + + -

Usage:

-
   cat foo | curl -F 'x=<-' $SCRIPT_URI
-

Source:

- -

Latest uploads:

+

NAME

+

vpaste: Vim enabled pastebin

+ +

SYNOPSIS

+
<command> | curl -F 'x=<-' $SCRIPT_URI
+ +

DESCRIPTION

+

Add ?option[=value] .. to make your text a rainbow.

+ +

OPTIONS

+
+
ft, filetype={filetype}
+
A filetype to use for highlighting, see FILETYPES
+
bg, background={light|dark}
+
Background color to use for the page
+
et, expandtab
+
Expand tabs to spaces
+
ts, tabstop=[N]
+
Number of spaces to use for tabs when et is set
+
...
+
See :help modeline for more information
+
+ +

FILETYPES

+
[+] $filetypes
+ +

SOURCE

+ + +

LATEST UPLOADS

+ EOF @@ -83,10 +155,6 @@ EOF pathinfo="${SCRIPT_URL/*vpaste\/}" boundary="${CONTENT_TYPE/*boundary\=/}" -# Print out a generic header -echo Content-Type: text/html; charset=UTF-8 -echo - if [ "$pathinfo" ]; then do_print "$pathinfo" elif [ "$CONTENT_TYPE" ]; then diff --git a/vpaste b/vpaste new file mode 100755 index 0000000..79cc633 --- /dev/null +++ b/vpaste @@ -0,0 +1,12 @@ +#!/bin/bash +uri="http://andy753421.ath.cx/vpaste/" +if [ "$1" ]; then + out=$(curl -F "x=<$1" "$uri") +else + out=$(curl -F 'x=<-' "$uri") +fi +echo "$out" +if [ -x "`which xclip 2>/dev/null`" -a "$DISPLAY" ]; then + echo -n "$out" | xclip -i -selection primary + echo -n "$out" | xclip -i -selection clipboard +fi -- 2.43.2