Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # ssup - upload screenshot
- # brew install pngpaste imagemagick
- set -x # Show commands as they are run.
- set -e # Exit on error.
- # Generate random file name for image.
- IMAGE_NAME=$(head -c 40 /dev/urandom | base64 | perl -pe 's~\W~~g' | head -c 15)
- TEMP_FILE="/tmp/${IMAGE_NAME}.png"
- pngpaste "$TEMP_FILE"
- DIMENSIONS=$(half-image-dimensions $TEMP_FILE)
- URL="https://curi.us/img/$IMAGE_NAME-${DIMENSIONS}.png"
- UPLOAD_PATH="/home/curi/img/${IMAGE_NAME}-${DIMENSIONS}.png"
- chmod 444 "$TEMP_FILE"
- if scp -P 44222 "$TEMP_FILE" "curi@ssh.curi.us:${UPLOAD_PATH}"
- then chmod 644 "$TEMP_FILE"
- else
- chmod 644 "$TEMP_FILE"
- say "oh my god the file name was a duplicate"
- exit 1
- fi
- echo -n "$URL" | pbcopy
- say "image uploaded"
- # half-image-dimensions script:
- # #!/usr/bin/env ruby
- #
- # # input: image file name
- # # output: image dimensions string like: 1920x1080
- # # output is half the real dimensions, rounded down, for getting retina stuff scaled down
- #
- # results = `sips -g pixelHeight -g pixelWidth #{ARGV[0]}`
- #
- # results =~ /pixelHeight: (\d+)/
- # h = ($1.to_f/2.0).to_i
- # results =~ /pixelWidth: (\d+)/
- # w = ($1.to_f/2.0).to_i
- #
- # print "#{w}x#{h}"
- # old script that makes a 50% size image and a retina image
- # Make sure a file with this name doesn't already exist.
- # Shouldn't happen with the length of random name we're using.
- # if curl --head "$URL" | head -1 | grep "200 OK" >/dev/null; then
- # say "duplicate file name"
- # exit 1
- # fi
- #
- # ORIGINAL_FILE="/tmp/${IMAGE_NAME}-has2x@2x.png"
- # CONVERTED_FILE="/tmp/${IMAGE_NAME}-has2x.png"
- #
- # # Copy image from clipboard to temp directory.
- # pngpaste "$ORIGINAL_FILE"
- #
- # # convert -resize 50% "$ORIGINAL_FILE" "$CONVERTED_FILE"
- #
- # # scp won't copy over read-only files
- # chmod 444 "$ORIGINAL_FILE" "$CONVERTED_FILE"
- #
- # ## CHANGE THE LINE BELOW to use the upload command of your choice.
- # if scp -P 44222 "$ORIGINAL_FILE" "$CONVERTED_FILE" curi@ssh.curi.us:/home/curi/img/
- # then chmod 644 "$ORIGINAL_FILE" "$CONVERTED_FILE"
- # else
- # chmod 644 "$ORIGINAL_FILE" "$CONVERTED_FILE"
- # say "oh my god the file name was a duplicate"
- # exit 1
- # fi
- #
- # # Copy URL to clipboard.
- # echo -n "$URL" | pbcopy
- #
- # say "image uploaded"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement