added UA header, and Authorization header based on DPASTE_API_TOKEN env var
1 files changed, 19 insertions(+), 10 deletions(-)

M +19 -10
@@ 1,18 1,20 @@ 
+# getopts code adapted from
-# Usage info
 show_help() {
 cat << HELP
-Usage: $(basename $0) [-h] [-s SYNTAX] [-t TITLE] [-e EXPIRY]
+Usage: $(basename "$0") [-h] [-s SYNTAX] [-t TITLE] [-e EXPIRY]
 Send stdin to, optionally setting syntax/title/expiry.
 Resulting item will be opened in your browser.
+If DPASTE_API_TOKEN is set in the environment, it will be used
+for authentication.
-# Process the options
-# (getopts code adapted from
-# Trailing colon on option name means it expects a value
+# Set User-Agent header, per TOS
+params="-A ''"
 while getopts hs:t:e: opt; do
     case $opt in

@@ 33,14 35,21 @@ while getopts hs:t:e: opt; do
 shift "$((OPTIND-1))"
-echo "Paste your content now, ^D to submit.\n---"
+echo "Paste your content now, ^D to submit."
-# make the API call
-url=$(curl -s -F "content=<-" $params
+# Make the API call, passing stdin to 'content' param
+if [ -z $DPASTE_API_TOKEN ]
+    url=$(curl -s -F "content=<-" $params
+    echo "(Using DPASTE_API_TOKEN from environment)"
+    url=$(curl -s -H "Authorization: Bearer $DPASTE_API_TOKEN" -F "content=<-" $params
 echo "---"
 echo $url
-# open in browser
+# Open in browser
 if [ -x "$(command -v xdg-open)" ];
     xdg-open $url