views:

419

answers:

3

I got this far:

:~ curl -u username:password -d status="new_status" http://twitter.com/statuses/update.xml

Now, how can I alias this with variables so I can easily twit from Terminal? How can I make the alias working through different sessions (when I close Terminal aliases reset).

Thanks!

+1  A: 

what about putting it a file and using argument 1 as $1:

# tweet.sh "post my status, moron!":
curl -u username:password -d status="$1" http://twitter.com/statuses/update.xml

will that work?

dusoft
+2  A: 

You clearly have the alias command: stick it in your ~/.bashrc and it will be set up when your bash shell starts. (.shrc should also work for sh-like shells.)

If you stick it in a script file as the previous answer suggests:

(a) add the line

#!/bin/sh

at the top;

(b) make sure it's on your path or you'll have to type the whole path to the script when you want to run it.

(c) to make it executable,

chmod +x tweet.sh
ijw
A: 

You need to create a file in your home directory that will get referenced each time a new terminal opens.

Do a bit of research as to what to name the file, according to what type of shell you are using (tcsh looks for a file called .tcshrc while bash looks for .bashrc).

Once you have that file, make it executable by running:

chmod +x name_of_file

Then, in that file, create your alias (again, you'll need to research how to do this depending on what type of shell you are using). For tcsh, my alias looks like this:

alias tw 'curl -u username:password -d status=\!^ http://twitter.com/statuses/update.xml'

Bash aliases use an equals sign. A bash alias would look something more like this:

alias tw='curl -u username:password -d status=\!^ http://twitter.com/statuses/update.xml'

Note the change in the command after "status=". The \!^ tells the line of code to insert the first argument passed after the alias itself.

Save your file.

You could then run an update to twitter by typing the following in a new terminal:

tw 'my first post to twitter via the terminal, using aliases'

Don't forget to escape 'special' characters (like exclamations) with the escape character, \ (i.e. \!)

i4n