annabunches.net/_posts/technology/2009-07-02-twitter-from-command-line.html

16 lines
1.9 KiB
HTML
Raw Normal View History

2016-04-11 22:01:00 +00:00
---
layout: post
title: Twitter from the command line
date: '2009-07-02T11:38:00.000-04:00'
author: Anna Wiggins
tags:
- programming
- linux
- twitter
- Technology
modified_time: '2013-10-22T11:19:50.705-04:00'
blogger_id: tag:blogger.com,1999:blog-4209116010564764361.post-6156350980105195782
blogger_orig_url: http://www.stringofbits.net/2009/07/twitter-from-command-line.html
---
I've recently started playing with twitter. A nice way to use it via the command-line (using curl) was suggested <a href="http://binnyva.blogspot.com/2007/03/using-twitter-part-1-command-line.html">here</a>. I have taken that and improved slightly on it.<br/><br/><a name='more'></a><br/><br/>Here is the result:<br/><br/><blockquote><code>#!/bin/sh<br/>echo -n "twitter&gt; "<br/>read text<br/><br/>while [ ${#text} -gt 140 ]; do<br/><br/>echo<br/>echo "Message too long; used ${#text}/140 characters."<br/>echo<br/>echo -n "twitter&gt; "<br/>read text<br/><br/>done<br/><br/>echo<br/>echo "Message is ${#text}/140 characters.  Press enter to post, or Ctrl+C to cancel."<br/>read<br/><br/>curl --basic --user "username:password" --data-ascii "status=`echo $text|tr ' ' '+'`" "http://twitter.com/statuses/update.json" &amp;&gt; /dev/null<br/></code><br/></blockquote><br/><br/>To use the script, copy all of that into a file somewhere in your path, then make the file executable (e.g., <code>chmod 755 /usr/local/bin/twitter</code>).  Now you can type 'twitter', type in your tweet, and you're done!<br/><br/>I even set up fluxbox so that mod4+t launches a terminal with the script running.  To do that, I added this to ~/.fluxbox/keys:<br/><br/><blockquote><br/><code><br/>Mod4 t :Exec xterm -e "twitter"<br/></code><br/></blockquote><br/><br/>If you're not familiar with 'mod4', it is the Windows key on most PC keyboards.<br/><br/>I'll eventually get around to writing a slightly more full-featured twitter updater in c or c++.  Until then, enjoy this script!