Created
October 23, 2011 18:57
-
-
Save andres-erbsen/1307715 to your computer and use it in GitHub Desktop.
Bash API for snurl.com URL shortening service (old)
This file contains 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 | |
# SNURL_KEY=your-SNURL_KEY-here | |
# SNURL_USER=username | |
if [ "x${SNURL_KEY}" == "x" ] | |
then | |
echo "You need set set sn.im API key, preferably by appending 'export SNURL_KEY=mykey' to .bashrc file. To get one you have to register at sn.im" | |
exit 1 | |
fi | |
snurl() | |
{ | |
if [ "$#" -eq "1" ] | |
then | |
echo `curl -d"snipuser=${SNURL_UESR}&snipapi=${SNURL_KEY}&snipformat=simple&sniplink=${1}" http://snipurl.com/site/getsnip` | |
else | |
if [ "$#" -eq "2" ] | |
then | |
echo `curl -d"snipuser=${SNURL_UESR}&snipapi=${SNURL_KEY}&snipformat=simple&sniplink=${1}&snipnick=${2}" http://snipurl.com/site/getsnip` | |
fi | |
fi | |
} | |
if [ "$#" -eq "0" ] | |
then | |
input=`xclip -selection=secondary -o` | |
else | |
input=`echo $@` | |
fi | |
if [ "x${input}" != "x" ] | |
then | |
shorturl=`snurl $input` | |
shorturl=`echo $shorturl | sed 's:snipurl.com:sn.im:'` | |
notify-send --icon="stock_internet" "Shortened!" ${shorturl}" (Ctrl + V)" | |
echo $shorturl | xclip -selection c | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment