Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
On a Mac, how can I group together commands I want run into a alias?

I have been using aliases for a while now but can't seem to figure out how to 'chain' commands properly. For instance, is there a way to type in one alias and have it chain multiple commands, like this?

'cd /Applications/MAMP/htdocs/V3/wp-content/themes/V3/'
mate .
open /Applications/MAMP/MAMP.app/
open -a Safari http://localhost:8888/
share|improve this question

marked as duplicate by Daniel Beck, slhck, techie007, studiohack Oct 30 '11 at 3:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer

up vote 4 down vote accepted

Use shell functions:

function mampMate() {
    cd /Applications/MAMP/htdocs/V3/wp-content/themes/V3/
    mate .
    open /Applications/MAMP/MAMP.app/
    open -a Safari http://localhost:8888/
}

Add these to your .bash_profile and run by entering

mampMate

You can even pass parameters and access them using their index as $1, $2, etc.

function foo() {
    echo "1: $1"
    echo "2: $2"
}

$ foo bar baz
1: bar
2: baz

One step further, and making your script more independent of your preferred shell, are scripts. Create a file named mampMate.sh and add the following:

#!/usr/bin/env bash
cd /Applications/MAMP/htdocs/V3/wp-content/themes/V3/
mate .
open /Applications/MAMP/MAMP.app/
open -a Safari http://localhost:8888/

This won't change your working directory though, as it won't affect your shell session.

Run chmod +x mampMate.sh and place it in a directory on your $PATH.

share|improve this answer
    
Perfect, thank you for the explanation! –  Tom Wahlin Oct 29 '11 at 19:56
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.