Last active
August 29, 2015 14:22
-
-
Save CaptainBern/0feac9a922ecc328e098 to your computer and use it in GitHub Desktop.
Little shell script to upload stuff to hastebin easier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HASTE_URL="http://hastebin.com/" | |
HASTE_UPLOAD_URL=$HASTE_URL'documents/' | |
raw=false | |
noclip=false | |
function help() { | |
echo "" | |
echo " -r, --raw" | |
echo " prints the raw link" | |
echo "" | |
echo " -n, --noclip" | |
echo " prevents this script from overriding your latest clipboard" | |
echo "" | |
exit | |
} | |
function haste() { | |
contents=$(cat $1) | |
# TODO: check if file exists? | |
echo $(curl -X POST -s -d "$contents" $HASTE_UPLOAD_URL) | |
} | |
function makeUrl() { | |
code=$(echo "$1" | awk -F '"' '{print $4}') | |
if [ $2 = true ] | |
then | |
url=$HASTE_URL'raw/'$code | |
else | |
url=$HASTE_URL$code | |
fi | |
echo $url | |
} | |
until [ -z $1 ] | |
do | |
case $1 in | |
-h | --help ) | |
help | |
;; | |
-r | --raw ) | |
raw=true | |
;; | |
-n | --noclip ) | |
noclip=true | |
;; | |
* ) | |
result=$(haste $1) | |
url=$(makeUrl $result $raw) | |
echo $url | |
if [ $noclip = false ] | |
then | |
echo "Copying to clipboard..." | |
echo "$url" | xclip -sel clip | |
fi | |
;; | |
esac | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment