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: $1; charset=UTF-8"
43 # Format a file for viewing
47 elif [ -f "db/$1" ]; then
49 trim='1d' # sed command to remove cruft
51 echo "Status: 404 Not Found"
53 echo "File '$1' not found"
58 if [[ "$REQUEST_URI" == *'?'* ]]; then
59 # Create a temp file with the provided modeline
62 cat "$input" >> "$tmp"
63 get_modeline >> "$tmp"
65 # - I have some plugins in ~/.vim
66 # - Run ex in screen to trick it into thinking that it
67 # has a real terminal, not that we also have to set
68 # term=xterm-256color in vimrc
70 screen -D -m ex -u vimrc \
90 output="$(mktemp db/XXXXX)"
91 uri="$SCRIPT_URI$(basename "$output")${QUERY_STRING:+"?"}"
92 (get_modeline; cut_file "$1") > "$output"
93 echo "Status: 302 Found"
102 ls /usr/share/vim/vim{72,files}/syntax/ /home/andy/.vim/after/syntax/ |
103 sed -n 's/.vim$//p' | sort | uniq
105 uploads=$(ls -t db | head -n 5 | sed "s!^!$SCRIPT_URI!")
112 * { margin:0; padding:0; }
114 h4 { margin:1em 0 0 0; }
115 p,ul,dl,dd,pre,blockquote { margin:0 0 0 2em; }
116 dt { font-weight:bold; padding:0.5em 0 0 0; }
117 blockquote { width:50em; font-size:small; }
121 <form id="form" method="post" action="?" enctype="multipart/form-data">
122 <textarea name="text" style="width:100%; height:20em;"></textarea>
124 <select onchange="document.getElementById('form').action =
125 document.location + '?ft=' + this.value;">
126 <option value="" selected="selected" disabled="disabled">Filetype</option>
127 <option value="">None</option>
128 $(for ft in $filetypes; do
129 echo "<option>$ft</option>"
132 <input type="submit" value="Paste">
137 <p>vpaste: Vim enabled pastebin</p>
140 <pre> vpaste file [option=value,..]</pre>
141 <pre> <command> | vpaste [option=value,..]</pre>
143 <pre> <command> | curl -F 'x=<-' $SCRIPT_URI[?option=value,..]</pre>
146 <p>Add <b>?[option[=value],..]</b> to make your text a rainbow.</p>
147 <p>Options specified when uploading are used as defaults.</p>
151 <dt>ft, filetype={filetype}</dt>
152 <dd>A filetype to use for highlighting, see above menu for supported types</dd>
153 <dt>bg, background={light|dark}</dt>
154 <dd>Background color to use for the page</dd>
155 <dt>et, expandtab</dt>
156 <dd>Expand tabs to spaces</dd>
157 <dt>ts, tabstop=[N]</dt>
158 <dd>Number of spaces to use for tabs when <b>et</b> is set</dd>
160 <dd>See :help modeline for more information</dd>
165 <li><a href="vpaste?ft=sh">vpaste</a>
166 <li><a href="index.cgi?ft=sh">index.cgi</a>
167 <a href="vimrc?ft=vim">vimrc</a>
168 <a href="htaccess?ft=apache">htaccess</a>
169 <li><a href="2html-et.patch?ft=diff">2html-et.patch</a>
172 <h4>LATEST UPLOADS</h4>
173 <ul>$(for uri in ${uploads[@]}; do
174 echo "<li><a href='$uri'>$uri</a>"
182 pathinfo="${SCRIPT_URL/*vpaste\/}"
184 if [ "$pathinfo" ]; then
186 elif [ "$CONTENT_TYPE" ]; then
187 do_upload ${CONTENT_TYPE/*boundary\=/}