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...
You can do this with shell profiles in Terminal.app.
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.You could create a symbolic link (which is like an alias in OS X, or shortcut in Windows) in your home directory, which is by default where your Terminal opens up.
Let's say your program source files are located in /usr/bin/myapps/. And your home directory is /users/Frank (you can reference your home directory by using the path /~ as well).
When you are in your home directory (/~), run the command
What this does is create a symbolic link called "project" to the location /usr/bin/myapps. You can then cd to project (cd /~/project) and wind up in /usr/bin/myapps.
This is the easiest fix, as it is temporary and can be removed easily. I believe you can just
To delete the symlink.
You can use an alias in your ~/.profile:
An alias can then be used just like any command. Type:
and you're there!
This way you don't have a softlink polluting your $HOME, and you can jump there anytime you like.
There's a similar question on Stack Overflow.
Open terminal here in Mac OS finder
Personally I don't like the GUI or AppleScript based solutions I see here. What I'd do is use the best unix command under OS X:
open
. E.G.You can adapt this by changing
/usr/bin/screen
to a command of your own making. So make a file called~/srcTerm.sh
and put these commands in it:Then issue:
open -a /Applications/Utilities/Terminal.app ~/srcTerm.sh
I know that looks cumbersome, so now edit
~/.bash_profle
and next to any otheralias
commands setup a new alias like:Next time you login, or source that file you can use the command
popupsrc
as a shortcut.Now you might be saying to yourself, "But
dlamblin
, this assumes I already have a terminal window open and am currently working on the command line. That's really not the case I was asking for. I was looking for something like an icon like Terminal that I can change the behavior of." And to that I might say something like: "Well, get all GUI-mousey here and find the~/srcTerm.sh
file in your finder, 'Get Info' about it, and change the 'Open with:' option to be 'Other...' then 'Enable all applications' and choose theTerminal
application. Do not select 'Change All...'. Now you can double click that file to pop up your terminal. You can stick that on your dock, in a quick folder (a.k.a. stack), or even type it's name into spotlight (accessible everywhere with Command-Space) and hit enter."Funny, I have used all 3 of the answers so far ;)
Here's another option: use applescript. You can create applescripts that open a window in the current finder directory for example.
I have a bunch of applescripts like that and I tied them to hotkeys with Quicksilver (or butler)
by default, I use a hotkeys that opens a terminal in the current finder directory, but only if finder is the frontmost application. Otherwise I simply get a fresh window. Then I also have scripts that open ssh sessions to certain servers and reconnect to a screen session. With the -x option to screen, you can have multiple erminal windows lookng at the same server terminal, great :)
EDIT:
This is the script I wrote which opens a new window, going into the current Finder directory if Finder is the currently active application:
To use it, open Script Editor and paste it in. Then save it somewhere convenient (I use ~/Library/Scripts) and tell QuickSilver, Butler or Google Quick Search Bar to run it. With QS and Butler you can set global shortcut keys as well.
Hope this helps,
Wout.
Not a solution really but did you know you can drag and drop a folder or file in to the terminal and it will insert the path to the item
eg type "cd" and the drop the folder and then hit return
If the problem is simply that you have to start every session in the terminal with this:
cd /a/very/very/annoyingly/long/path/name
, then I can think of two solutions.Put this at the bottom of your
.profile
file (it's in your user's home directory):cd /a/very/very/annoyingly/long/path/name
Edit your
CDPATH
. This method gives you quick tab-completable directory changes Mine looks like this, for example, since most of my shell work is in the two directories 'iliumSvn' or 'unix.varia'.:export CDPATH='.:~:~/iliumSvn/:~/unix.varia'
I think that 2 is cleaner and better in the long run, but either should work fine. The issue with 1 is that if your work habits change, you will need to remember to remove that line, or it will drive you crazy every time you open a shell.
The way I do stuff like this is with DTerm http://www.decimus.net/dterm.php this way you can just hit a KeyCombo from the Editor you are working in (Textmate in my case) and you get a Command line for this location. You can than issue a Command (ie make) and thats it! If you want to open a real Terminal there than you can just hit Command+Return instead of Return and your command is executed in this Directory in a new Terminal Window. Seems to me much easier than fiddling with a bunch of Paths etc.