Terminal window in Mac OS X

command-line-interfacemac-osx

Is it possible to to create a shortcut to open a terminal window to a specific directory? I'm using gcc a lot to build small C programs but it is annoying to have to navigate to the directory where my source code is. Is there anyway to configure an short cut (or anything) to terminal to open the window in a given directory?

Update: This problem is still eluding me. The most voted answer is the one I've just tried to implement. But, I'm apparently having trouble putting together what would be the $PROJECTDIR path.

Lets assume that the files are in something like the following location:

 /Documents/SVN Working Copies/School/Term-1/CSC-373/

I can get there when I cd to every thing by itself but I've been using the wild card:

cd doc*
cd svn*
cd *
cd *

What I tried was (things like):

cd /Documents/SVN Working Copies/School/Term-1/CSC-373/  

(again, in place of $PROJECTDIR.) When I open the terminal window, I have access to Documents so I figured I would when creating the new profile…

Best Answer

You can do this with shell profiles in Terminal.app.

  1. Select the Terminal menu, go to Preferenes.
  2. Select Settings from the buttons above.
  3. Either select an existing profile or create a new one
  4. In the Shell tab, check the Run Command box and enter cd $PROJECTDIR where $PROJECTDIR is the path to your project.
  5. Check Run inside shell

Now from the New Window or New Tab menu when you create a window or tab with the profile you modified, it will execute the cd command inside your bash shell and change your directory to the one you want.

This is handy because you can create many different profiles for different tasks. If you want to run a large number of commands when starting up a profile, put then in file in ~/bin/ or somewhere else in your home directory and execute those instead. You can also use the semicolon ; to run multiple commands if you've checked the Run inside shell checkbox.