Last active
December 20, 2015 22:29
-
-
Save jasonbouffard/6205031 to your computer and use it in GitHub Desktop.
Takes your current clipboard/pasteboard and pastes it to a text file in a public Dropbox directory. Shortens the url and puts it in your clipboard for quick pasting into a IM/Email.
This file contains hidden or 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 | |
DATE=$(date +"%Y-%m-%d"); | |
TIME=$(date +"%I.%M.%S"); | |
AMPM=$(date +"%p"); | |
FILENAME=Paste\ $DATE\ at\ $TIME\ $AMPM.txt; | |
# You can export you DROPBOX_USER_ID in your .bash_profile | |
# or hardcode it here by replacing YOURDROPBOXUSERID | |
DB_USER_ID=${DROPBOX_USER_ID-YOURDROPBOXUSERID}; | |
# Make sure you create the Screenshots directory in | |
# your public directory | |
DB_BASE_DIR=~/Dropbox/Public/Pastes; | |
DB_BASE_URL=https://dl.dropboxusercontent.com/u; | |
pbpaste -Prefer txt > "$DB_BASE_DIR/$FILENAME"; | |
# file may not have been created for one reason or another | |
if [ -f "$DB_BASE_DIR/$FILENAME" ]; | |
then | |
URL_FILENAME=$(python -c "import urllib; print urllib.quote('''$FILENAME''')"); | |
URL_LONG="$DB_BASE_URL/$DB_USER_ID/Pastes/$URL_FILENAME"; | |
# copy long url, if you paste before the shortener returns | |
echo $URL_LONG | pbcopy; | |
# shorten url via google | |
URL_SHORT=$(curl https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d "{\"longUrl\": \"$URL_LONG\"}" 2>/dev/null | grep goo.gl | cut -f 4 -d '"'); | |
if [ -n "$URL_SHORT" ]; then | |
# we have a short url, copy it | |
echo $URL_SHORT | pbcopy; | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment