From a07ccda119f77da7aae5aa22bd9c9dfd687618bf Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Wed, 7 Oct 2009 05:43:33 +0000 Subject: [PATCH] --- index.cgi | 70 ++++++++++++++++++++++++++++++++++--------------------- vimhi.sh | 17 -------------- vpaste | 6 ++--- 3 files changed, 47 insertions(+), 46 deletions(-) delete mode 100755 vimhi.sh diff --git a/index.cgi b/index.cgi index a074f8a..0c5eeba 100755 --- a/index.cgi +++ b/index.cgi @@ -13,8 +13,13 @@ # GNU General Public License for more details. # Remove url codings form stdin -function urldecode { - sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g; s/[,&]/ /g' | xargs echo -e +function get_modeline { + modeline=$( + echo "$QUERY_STRING" | + sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g; s/[,&]/ /g' | + xargs echo -e + ) + echo "vim: $modeline" } # Extract an uploaded file from standard input @@ -46,7 +51,8 @@ function do_print { if [ -f "$1" ]; then input="$1" elif [ -f "db/$1" ]; then - input="db/$1" + input="db/$1" + trim='1d' # sed command to remove cruft else echo "Status: 404" start_text @@ -54,22 +60,32 @@ function do_print { return fi - modeline="$(echo $QUERY_STRING | urldecode)" - 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 + if [[ "$REQUEST_URI" == *'?'* ]]; then + # Create a temp file with the provided modeline output="$(mktemp)" + tmp="$(mktemp)" + cat "$input" >> "$tmp" + get_modeline >> "$tmp" + + # - I have some plugins in ~/.vim + # - Run ex 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" + screen -D -m ex -u vimrc \ + '+$d|'$trim \ + '+TOhtml' \ + "+sav! $output" \ + '+qall!' \ + "$tmp" + start_html cat "$output" + rm "$tmp" "$output" + else + start_text + sed "$trim" "$input" fi } @@ -78,9 +94,9 @@ function do_print { function do_upload { output="$(mktemp db/XXXXX)" uri="$SCRIPT_URI$(basename "$output")" - cut_file "$1" > "$output" + (get_modeline; cut_file "$1") > "$output" start_text - echo "$uri" + echo "$uri${QUERY_STRING:+"?"}" } # Default index page @@ -101,8 +117,7 @@ cat - < @@ -110,10 +125,14 @@ cat - <vpaste: Vim enabled pastebin

SYNOPSIS

-
<command> | curl -F 'x=<-' $SCRIPT_URI
+
 vpaste file [option=value,..]
+
 <command> | vpaste [option=value,..]
+
+
 <command> | curl -F 'x=<-' $SCRIPT_URI[?option=value,..]

DESCRIPTION

-

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

+

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

+

Options specified when uploading are used as defaults.

OPTIONS

@@ -129,16 +148,12 @@ cat - <See :help modeline for more information
-

FILETYPES

-
[+] $filetypes
-

SOURCE

@@ -146,6 +161,9 @@ cat - <$(for uri in ${uploads[@]}; do echo "
  • $uri" done) + +

    FILETYPES

    +
    $filetypes
    EOF diff --git a/vimhi.sh b/vimhi.sh deleted file mode 100755 index 7daefe2..0000000 --- a/vimhi.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2009 Andy Spencer - Public domain - -input="$1" -output="$2" -modeline="$3" - -# Add the modeline inline to the file then -# remove it after the file is loaded. -ex -u vimrc \ - "+1d" \ - "+TOhtml" \ - "+sav! $output" \ - "+qall!" \ - <(echo "vim: $modeline"; cat "$input") \ - 2>/dev/null 1>&2 diff --git a/vpaste b/vpaste index 79cc633..0e87323 100755 --- a/vpaste +++ b/vpaste @@ -1,9 +1,9 @@ #!/bin/bash uri="http://andy753421.ath.cx/vpaste/" -if [ "$1" ]; then - out=$(curl -F "x=<$1" "$uri") +if [ -f "$1" ]; then + out=$(curl -F "x=<$1" "$uri?$2") else - out=$(curl -F 'x=<-' "$uri") + out=$(curl -F 'x=<-' "$uri?$1") fi echo "$out" if [ -x "`which xclip 2>/dev/null`" -a "$DISPLAY" ]; then -- 2.43.2