]> Pileus Git - vpaste/commitdiff
Set dropdown using GET param
authorAndy Spencer <andy753421@gmail.com>
Fri, 19 Aug 2011 04:46:23 +0000 (04:46 +0000)
committerAndy Spencer <andy753421@gmail.com>
Fri, 19 Aug 2011 04:46:23 +0000 (04:46 +0000)
index.cgi

index 39a868b5b930b76a881023d5b679d2669a50384e..7347e9e2b41a54890c233b363e6dc51610c0a7fc 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
 # Remove url codings from stdin
 function get_modeline {
        echo "$QUERY_STRING" |
-       sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g; s/[,&]/ /g' |
+       sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g; s/[,&?]/ /g' |
        xargs echo -e
 }
+function get_param {
+       get_modeline | awk -v "key=$1" 'BEGIN{RS=" "; FS="="}; $1 ~ key {print $2}'
+}
 
 # Extract an uploaded file from standard input
 #   $1 is the name of the input to extract
@@ -157,6 +160,7 @@ function do_help {
                sort | uniq
        )
        uploads=$(ls -t db | head -n 5)
+       filetype=$(get_param '^(ft|filet(y(pe?)?)?)$')
 
        header text/html
        cat <<-EOF
@@ -185,11 +189,14 @@ function do_help {
                <textarea name="text" cols="80" rows="25" style="width:100%; height:20em;"></textarea>
                <select onchange="document.getElementById('form').action =
                    document.location + '?ft=' + this.value;">
-               <option value="" selected="selected" disabled="disabled">Filetype</option>
-               <option value="">None</option>
-               $(for ft in $filetypes; do
-                   echo "<option>$ft</option>"
-               done)
+                       <option value="" disabled="disabled">Filetype</option>
+                       <option value="">None</option>
+                       $(for ft in $filetypes; do
+                               echo "<option$(
+                               [ "$ft" = "$filetype" ] &&
+                                       echo ' selected="selected"'
+                               )>$ft</option>"
+                       done)
                </select>
                <input type="submit" value="Paste" />
                </div>