Skip to content

Instantly share code, notes, and snippets.

@madprops
Last active June 14, 2019 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madprops/c53de571dd13ec07f5616077939cbb40 to your computer and use it in GitHub Desktop.
Save madprops/c53de571dd13ec07f5616077939cbb40 to your computer and use it in GitHub Desktop.
Bash script to upload to different sources
#! /bin/bash
# This requires dropbox_uploader.sh for dropbox support
# You can create context menu entries in your DE or keyboard shortcuts for this
# Add your Imgur client ID
function upload_image
{
client_id="yourImgurClientID"
link=$(curl -s --request POST --url https://api.imgur.com/3/image --header \
"Authorization: Client-ID ${client_id}" --header "content-type: multipart/form-data;" \
-F "image=@${1}" | jq -r '.data.link')
$(echo "$link" | tr -d '\n' | xsel -ib)
notify-send "Image Uploaded"
}
function upload_text
{
dtime=`date '+%Y-%m-%d-%H:%M:%S'`
id=$(curl -s --data "content=${1}&comment=${dtime}&mode_name=JavaScript" \
https://paste.merkoba.com/save.php | jq -r '.url')
url="https://paste.merkoba.com/${id}"
echo $url | tr -d '\n' | xsel -ib
notify-send "Text Uploaded"
}
function upload_file
{
fname=$(basename "$1")
dtime=`date '+%Y-%m-%d-%H:%M:%S'`
filename="${dtime}_${fname}"
/home/yo/scripts/dropbox_uploader.sh upload "$1" "$filename"
/home/yo/scripts/dropbox_uploader.sh share "$filename" | \
perl -ne 's/(.*?)(?=https)//; print' | tr -d '\n' | xsel -ib
notify-send "File Uploaded"
}
function check_file
{
if [[ $1 == *.jpg ]] || [[ $1 == *.jpeg ]] || [[ $1 == *.png ]] || [[ $1 == *.gif ]]; then
upload_image "$1"
elif $(file -bL --mime "$1" | grep -q '^text'); then
content=$(cat "$1")
upload_text "$content"
else
upload_file "$1"
fi
}
if [[ $# -gt 0 ]]; then
for file in "$@"
do
check_file "$file"
done
else
content=$(xsel -ob)
if [[ $content == "file://"* ]]; then
IFS=$'\n'; files=($content); unset IFS
for (( i=0; i<${#files[@]}; i++ ))
do
file=$(echo "${files[$i]#file://}")
check_file "$file"
done
else
upload_text "$content"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment