6

In GNOME Terminal of Ubuntu when you open a new tab the new shell will automatically start you in the current working directory of the active tab shell.

E.g. if in the active tab shell I am on ~/myproject and I open a new tab, the new shell will start on ~/myproject too.

As you can guess, this is very convenient when you work deep in the directory hierarchy.

Can I configure the OSX terminal to have this behaviour?

If not, is there any free (cocoa) terminal that does this?

3 Answers 3

7

You may use iTerm2 and just select in preferences to "reuse previous tab's directory"

enter image description here

2
  • I also recommend using iTerm2 as a Terminal replacement. I did come from the linux world, and finding a good gnome-terminal replacement for mac was a must.
    – mspasov
    Commented Mar 29, 2011 at 15:37
  • 2
    I'd like to add that this behavior can be configured in recent versions of Terminal.app as well.
    – Gerry
    Commented Aug 30, 2012 at 22:22
3

In recent OS X versions (Mavericks and Yosemite, not sure about earlier versions) in the Terminal.app preferences, "General" tab, there are options for "New windows open with" and "New tabs open with":

enter image description here

0
2

Here's my solution from a SuperUser question


Get the current environment in your clipboard:

env | pbcopy

Open up a new Terminal window and export those environment variables

for env in `pbpaste`; do export $env; done

And to ease the process, you could always alias it, like so

alias get_env="env | pbcopy"
alias set_env="for env in `pbpaste`; do export $env; done"

So that all you have to do is

get_env +N set_env


The accepted solution:

#!/bin/sh 
osascript <<END 
tell app "Terminal" to do script "cd \"`pwd`\"" 
END

Place it in one of the folders in your path, make it executable (chmod +x filename). You can then run the name of this script to open a new terminal window in the same directory.

1
  • The osascript approach is nice. But it opens the shell in a new window instead of a new tab.
    – m000
    Commented Mar 30, 2011 at 19:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .