Skip to content

Instantly share code, notes, and snippets.

@javierarce
Created November 8, 2012 13:39
Show Gist options
  • Save javierarce/4038854 to your computer and use it in GitHub Desktop.
Save javierarce/4038854 to your computer and use it in GitHub Desktop.
# Download file from URL + Upload to your server + Copy short URL to your clipboard
# Use it like this:
# gi http://25.media.tumblr.com/tumblr_md2j4a4Eot1rddgbmo1_1280.png
# And get something like this:
# tumblr_md2j4a4Eot1rddgbmo1_1280.png 100% 41KB 41.4KB/s 00:00
# Copied to the clipboard: http://goo.gl/ITEIG
function gi() {
url=$1
filename=$(basename "$url")
wget --no-verbose "$url"
scp "$filename" YOUR_SERVER_USERNAME@DOMAIN_URL.com:~/img;
curl \
-s https://www.googleapis.com/urlshortener/v1/url \
-H 'Content-Type: application/json' \
-d '{"longUrl": "'"http://DOMAIN_URL.com/DIRECTORY/$filename"'"}' | egrep -o 'http://goo.gl/[^"]*' | pbcopy
rm $filename
echo "Copied to the clipboard:" "\033[1;32m$(pbpaste)\033[m"
}
function scpp() {
scp "$1" YOUR_SERVER_USERNAME@DOMAIN_URL.com:~/img;
curl \
-s https://www.googleapis.com/urlshortener/v1/url\?key\=API_KEY \
-H 'Content-Type: application/json' \
-d '{"longUrl": "'"http://DOMAIN_URL.com/DIRECTORY/$1"'"}' | egrep -o 'http://goo.gl/[^"]*' | pbcopy
echo "Copied to the clipboard:" "\033[1;32m$(pbpaste)\033[m"
}
function scpp() {
scp "$1" YOUR_SERVER_USERNAME@DOMAIN_URL.com:~/img;
curl \
-s https://www.googleapis.com/urlshortener/v1/url \
-H 'Content-Type: application/json' \
-d '{"longUrl": "'"http://DOMAIN_URL.com/DIRECTORY/$1"'"}' | egrep -o 'http://goo.gl/[^"]*' | pbcopy
echo "Copied to the clipboard:" "\033[1;32m$(pbpaste)\033[m"
}
@javierarce
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment