Skip to content

Instantly share code, notes, and snippets.

@willowiscool
Created March 22, 2020 00:06
Show Gist options
  • Save willowiscool/7f54584f371b3a38d7708b93ac647354 to your computer and use it in GitHub Desktop.
Save willowiscool/7f54584f371b3a38d7708b93ac647354 to your computer and use it in GitHub Desktop.
Upload what's in the clipboard to S3 (interactive file name input)
#!/usr/bin/env bash
BUCKET="vityavv-imagebin"
target=$(xclip -sel clip -o -t TARGETS | tail -1)
mime="$target"
[[ "$mime" == *"/"* ]] || mime="text/plain"
filename=$(yad --entry --title "S3 Uploader" --center --text "S3 Uploader\nClipboard type is $target" --text-align=center --entry-label="Filename:" 2>/dev/null || echo "STOP THIS")
[ "$filename" == "STOP THIS" ] && exit 1
[ "$filename" == "" ] && exit 1
aws s3 ls "s3://$BUCKET" | grep $filename && {
yad --no-buttons --center --text "FILENAME ALREADY EXISTS: $filename"
exit 1
}
echo uploading
xclip -sel clip -o -t $target | aws s3 cp - "s3://$BUCKET/$filename" --content-type "$mime"
echo "https://$BUCKET.s3.amazonaws.com/$filename" | xclip -sel clip -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment