Command line twitter

I had half a thought that I might want to have a wee utility to alert me that other wee utilities had finished whatever it was they were doing. So seeing as I usually have at least one terminal window open at a time, a minimal command line tool for twittering follows. called ‘twit’.

It has a dependency on your having cURL installed.

$cat `which twit`
#!/bin/bash
# script to post to twitter

USER=username
PASS=password
UPDATE=$1
LEN=${#UPDATE}
SILENT=$2

if [ "$SILENT" == "" ]; then
	SILENT="1>/dev/null 2>&1"
fi

if [ $LEN -lt 140 ] ; then

	eval curl --basic --user $USER:$PASS --user-agent "twit/1.0" --data status=\"$UPDATE\" http://api.twitter.com/1/statuses/update.xml $SILENT

	if [ $? == 0 ]; then
		echo -e "Tweet Sent"
	fi
else
	echo -e "ERROR: tweet too long ($LEN)\a"
fi

#ends

Update: Since June 2010 when twitter dropped Basic Authentication, this no longer works. 🙁

Leave a comment