Found this tip over at macosxhints.com and also tlrobinson.net to be very useful. I don’t know how many times I’ve always open a new terminal with cmd-n and slowly cd into the current directory of the other terminal window.
However, both guides had something lacking from each other. The guide from macosxhints.com can’t be completed because I can’t find a function called rehash in Leopard and it can’t open a new terminal in another specified directory like the ones from tlrobinson.net. The guide from tlrobinson.net was almost perfect but it would fail to launch a new terminal if your current terminal path consist of spaces in the directory. (e.g. /directory1/directory with spaces/another directory). Therefore, I just merge both of their guides together to have the best of both worlds:
#!/bin/sh
if [ $# -ne 1 ]; then
PATHDIR=`pwd`
else
PATHDIR=$1
fi
osascript << END
tell app "Terminal" to do script "cd \"$PATHDIR\""
END
Just paste the above code in any directory you like. I created a folder ‘bin’ in my home directory to store all my custom executables and added the following into my .bash_profile:
export PATH="${HOME}/bin:${PATH}
I then also added the following in my .bash_profile
alias term="sh term.sh"
You can now either close your current terminal window and open a new one or do
source .bash_profile
to have the new changes in your .bash_profile to take effect on your current terminal.
With this, you can now open a new terminal window at your current directory with
term
or open a new terminal at another path with
term /somewhere/you/want/to/go
or even open multiple terminal windows with
term; term;
A majority of the guide above is taken from the authors of tlrobinson.net and macosxhints.com. Therefore, credits and appreciation must be given to both these sites: tlrobinson.net and macosxhints.com.