Skip to content

Instantly share code, notes, and snippets.

@andres-erbsen
Created October 23, 2011 18:57
Show Gist options
  • Save andres-erbsen/1307715 to your computer and use it in GitHub Desktop.
Save andres-erbsen/1307715 to your computer and use it in GitHub Desktop.
Bash API for snurl.com URL shortening service (old)
#!/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