Skip to content

Instantly share code, notes, and snippets.

@cfr
Created April 10, 2015 23:43
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 cfr/d5a939f704a009737225 to your computer and use it in GitHub Desktop.
Save cfr/d5a939f704a009737225 to your computer and use it in GitHub Desktop.
#!/bin/bash
lurl=$(pbpaste)
login=""
key=""
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ $lurl =~ $regex ]]
then
echo $lurl
else
if [[ $1 =~ $regex ]]
then
echo $1
lurl=$1
else
echo "No valid url in pbpaste/arg."
fi
fi
url="http://api.bitly.com/v3/shorten?login=$login&apiKey=$key&longUrl=$lurl&format=txt"
curl -s $url | tee >(pbcopy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment