diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2016-07-28 19:21:51 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2016-07-28 19:21:51 -0300 |
commit | f3c8ed6ea3bffbf81ec21203a7004a794a10262e (patch) | |
tree | 0dd0878103ab7a2ab55176818f41a5bfcf0526c6 | |
parent | d143a87c11c37f29a788cfd069bb8377f3203c04 (diff) | |
download | scripts-f3c8ed6ea3bffbf81ec21203a7004a794a10262e.tar.gz scripts-f3c8ed6ea3bffbf81ec21203a7004a794a10262e.tar.bz2 |
Adds scuttle
-rwxr-xr-x | scuttle | 72 |
1 files changed, 72 insertions, 0 deletions
@@ -0,0 +1,72 @@ +#!/bin/bash +# +# Post a link to a scuttle service. +# + +# Thanks https://gist.github.com/cdown/1163649 +function urlencode() { + # urlencode <string> + old_lc_collate=$LC_COLLATE + LC_COLLATE=C + + local length="${#1}" + for (( i = 0; i < length; i++ )); do + local c="${1:i:1}" + case $c in + [a-zA-Z0-9.~_-]) printf "$c" ;; + *) printf '%%%02X' "'$c" ;; + esac + done + + LC_COLLATE=$old_lc_collate +} + +# Parameters +BASENAME="`basename $0`" +URL="$1" +TAGS="$2" +shift 2 +DESC="$*" +TMP="${TMP:=/tmp}" + +# Syntax +if [ -z "$TAGS" ]; then + echo "usage: $BASENAME <url> <tags> <description>" + exit +fi + +# Config +source "$HOME/.custom/scuttle" || exit 1 + +# See http://www.wired.com/2010/02/using_the_delicious_api/ +CALL="$SCUTTLE_URL/api/posts/add?url=`urlencode $URL`" + +# Tags +TAGS="`echo $TAGS | sed -e 's/,/ /g'`" +TAGS="`urlencode "$TAGS"`" +TAGS="`echo $TAGS | sed -e 's/%2C/,/g'`" +CALL="$CALL&tags=$TAGS" + +# Description +if [ -z "$DESC" ]; then + DESC="`curl -s $URL | grep -i "<title>" | sed -e 's|<title>\(.*\)</title>|\1|' 2> /dev/null`" + echo "Fetched description: $DESC" +fi + +# Full API call +CALL="$CALL&description=`urlencode "$DESC"`" + +# Write config +CONF="`mktemp -t scuttle.XXXXXXXXXX -p $TMP`" +echo "url = $CALL" > $CONF +echo "user = $SCUTTLE_USER:$SCUTTLE_PASS" >> $CONF + +# Call curl +curl -s -K $CONF &> /dev/null + +# Status +STATUS="$?" + +# Teardown +rm $CONF +exit $STATUS |