]> Pileus Git - vpaste/commitdiff
updating vpaste
authorAndy Spencer <andy753421@gmail.com>
Wed, 7 Oct 2009 03:37:07 +0000 (03:37 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 7 Oct 2009 03:37:07 +0000 (03:37 +0000)
2html-et.patch [new file with mode: 0644]
index.cgi
vpaste [new file with mode: 0755]

diff --git a/2html-et.patch b/2html-et.patch
new file mode 100644 (file)
index 0000000..50d01b8
--- /dev/null
@@ -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)
index e8c14f132cba7ec5da44b19450feb60bbdd1418e..a074f8a0f3d7cfee91edf07737463f85a872376c 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
 
 # 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 - <<EOF
 <html>
+       <head>
+               <style>
+               * { margin:0; padding:0; }
+               body { margin:1em; }
+               h4 { margin:1em 0 0 0; }
+               p,ul,dl,dd,pre,blockquote { margin:0 0 0 2em; }
+               dt { font-weight:bold; padding:0.5em 0 0 0; }
+               blockquote { height:2pc; width:30em; font-size:smaller; overflow:hidden; }
+               blockquote:hover { height:auto; width:auto; }
+               </style>
+       </head>
        <body>
-       <p>Usage:</p>
-       <pre>   cat foo | curl -F 'x=<-' $SCRIPT_URI</pre>
-       <p>Source:</p>
-       <ul>
-       <li><a href="index.cgi?ft=sh">index.cgi</a>
-       <li><a href="vimhi.sh?ft=sh">vimhi.sh</a>
-       <li><a href="vimrc?ft=vim">vimrc</a>
-       <li><a href="htaccess?ft=apache">htaccess</a>
-       </ul>
-       <p>Latest uploads:</p><ul>
-       $(for i in $(ls -t db | head -n 5); do
-               uri="$SCRIPT_URI$i"
-               echo "<li><a href='$uri'>$uri</a>"
-       done)
-       </ul>
+               <h4>NAME</h4>
+               <p>vpaste: Vim enabled pastebin</p>
+
+               <h4>SYNOPSIS</h4>
+               <pre>&lt;command&gt; | curl -F 'x=<-' $SCRIPT_URI</pre>
+
+               <h4>DESCRIPTION</h4>
+               <p>Add <b>?option[=value] ..</b> to make your text a rainbow.</p>
+
+               <h4>OPTIONS</h4>
+               <dl>
+               <dt>ft, filetype={filetype}</dt>
+               <dd>A filetype to use for highlighting, see FILETYPES</dd>
+               <dt>bg, background={light|dark}</dt>
+               <dd>Background color to use for the page</dd>
+               <dt>et, expandtab</dt>
+               <dd>Expand tabs to spaces</dd>
+               <dt>ts, tabstop=[N]</dt>
+               <dd>Number of spaces to use for tabs when <b>et</b> is set</dd>
+               <dt>...</dt>
+               <dd>See :help modeline for more information</dd>
+               </dl>
+
+               <h4>FILETYPES</h4>
+               <blockquote><u>[+]</u> $filetypes</blockquote>
+
+               <h4>SOURCE</h4>
+               <ul>
+               <li><a href="vpaste?ft=sh">vpaste</a>
+               <li><a href="index.cgi?ft=sh">index.cgi</a>
+               <li><a href="vimhi.sh?ft=sh">vimhi.sh</a>
+               <li><a href="vimrc?ft=vim">vimrc</a>
+               <li><a href="htaccess?ft=apache">htaccess</a>
+               <li><a href="2html-et.patch?ft=diff">2html-et.patch</a>
+               </ul>
+
+               <h4>LATEST UPLOADS</h4>
+               <ul>$(for uri in ${uploads[@]}; do
+                       echo "<li><a href='$uri'>$uri</a>"
+               done)</ul>
        </body>
 </html>
 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 (executable)
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