3 # Copyright (C) 2009 Andy Spencer
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # Remove url codings form stdin
16 function get_modeline {
18 echo "$QUERY_STRING" |
19 sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g; s/[,&]/ /g' |
25 # Extract an uploaded file from standard input
26 # $1 is the boundary delimiter for the file
32 /^\\r$/ && st==1 {st=2};
34 # Remove trailing ^M's that come with CGI
37 # Print out a generic header
39 echo "Content-Type: text/html; charset=UTF-8"
43 # Print out a generic header
45 echo "Content-Type: text/plain; charset=UTF-8"
49 # Format a file for viewing
53 elif [ -f "db/$1" ]; then
55 trim='1d' # sed command to remove cruft
59 echo "File '$1' not found"
64 if [[ "$REQUEST_URI" == *'?'* ]]; then
65 # Create a temp file with the provided modeline
68 cat "$input" >> "$tmp"
69 get_modeline >> "$tmp"
71 # - I have some plugins in ~/.vim
72 # - Run ex in screen to trick it into thinking that it
73 # has a real terminal, not that we also have to set
74 # term=xterm-256color in vimrc
76 screen -D -m ex -u vimrc \
95 output="$(mktemp db/XXXXX)"
96 uri="$SCRIPT_URI$(basename "$output")"
97 (get_modeline; cut_file "$1") > "$output"
99 echo "$uri${QUERY_STRING:+"?"}"
105 ls /usr/share/vim/vim{72,files}/syntax/ /home/andy/.vim/after/syntax/ |
106 sed -n 's/.vim$//p' | sort | uniq
108 uploads=$(ls -t db | head -n 5 | sed "s!^!$SCRIPT_URI!")
115 * { margin:0; padding:0; }
117 h4 { margin:1em 0 0 0; }
118 p,ul,dl,dd,pre,blockquote { margin:0 0 0 2em; }
119 dt { font-weight:bold; padding:0.5em 0 0 0; }
120 blockquote { width:50em; font-size:small; }
125 <p>vpaste: Vim enabled pastebin</p>
128 <pre> vpaste file [option=value,..]</pre>
129 <pre> <command> | vpaste [option=value,..]</pre>
131 <pre> <command> | curl -F 'x=<-' $SCRIPT_URI[?option=value,..]</pre>
134 <p>Add <b>?[option[=value],..]</b> to make your text a rainbow.</p>
135 <p>Options specified when uploading are used as defaults.</p>
139 <dt>ft, filetype={filetype}</dt>
140 <dd>A filetype to use for highlighting, see FILETYPES</dd>
141 <dt>bg, background={light|dark}</dt>
142 <dd>Background color to use for the page</dd>
143 <dt>et, expandtab</dt>
144 <dd>Expand tabs to spaces</dd>
145 <dt>ts, tabstop=[N]</dt>
146 <dd>Number of spaces to use for tabs when <b>et</b> is set</dd>
148 <dd>See :help modeline for more information</dd>
153 <li><a href="vpaste?ft=sh">vpaste</a>
154 <li><a href="index.cgi?ft=sh">index.cgi</a>
155 <a href="vimrc?ft=vim">vimrc</a>
156 <a href="htaccess?ft=apache">htaccess</a>
157 <li><a href="2html-et.patch?ft=diff">2html-et.patch</a>
160 <h4>LATEST UPLOADS</h4>
161 <ul>$(for uri in ${uploads[@]}; do
162 echo "<li><a href='$uri'>$uri</a>"
166 <blockquote>$filetypes</blockquote>
173 pathinfo="${SCRIPT_URL/*vpaste\/}"
174 boundary="${CONTENT_TYPE/*boundary\=/}"
176 if [ "$pathinfo" ]; then
178 elif [ "$CONTENT_TYPE" ]; then
179 do_upload "$boundary"