36

When I have a Terminal window open, ⌘N opens a new one.

Is there any way to get the current directory in the new window to automatically be the same as it was on the window where I pressed ⌘N?

4 Answers 4

30

To accomplish this within a new window, go to Preferences within Terminal.app.

Within the General tab, you can adjust the behavior (you likely want to select Same Working Directory) for both new windows and new tabs.

Preferences

3
  • Oh, looks like I already had it enabled but must have messed it up somehow in my .bashrc. Thanks!
    – Bemmu
    Commented Mar 24, 2015 at 4:06
  • 3
    Three years later I found I just had some cd command at the end of said .bashrc, after removing that this started to work.
    – Bemmu
    Commented Mar 9, 2018 at 4:38
  • 1
    @Bemmu Ha. Glad you figured it out - been waiting... ;)
    – Scot
    Commented Mar 9, 2018 at 20:03
14

If you hit ⌘T in the Terminal, it will open another tab, which will be in the same directory as before :-).

You can easily switch between the tabs using keyboard shortcuts too like

- ⌘-Shift-[ and ⌘-Shift-]

Enjoy!

5
  • 1
    This should be the answer.
    – CJWEB
    Commented Nov 15, 2018 at 23:56
  • 2
    You can also then drag the tab out to a separate window if you didn't want it tabbed Commented Dec 13, 2018 at 9:20
  • This is the correct answer.
    – MoMo
    Commented Nov 12, 2019 at 15:23
  • This doesn't work for me. If I change directory in terminal and open a new tab the new tab is not in that directory.
    – smohadjer
    Commented Aug 4, 2020 at 8:05
  • @smohadjer look at your settings - there should be separate settings for 'New windows open with' and 'New tabs open with' - you can adjust those so that the behavior is more to your liking Commented Oct 3, 2022 at 2:31
7

The problem is that Terminal doesn't know anything about what directory you're in.

But the shell does! So you can type:

open -a /Applications/Utilities/Terminal.app .

and it will open a new window on your current directory.

If you want to do this a lot, put the following in ~/.bashrc:

alias openhere='open -a /Applications/Utilities/Terminal.app .'

Then, all you will have to type is openhere to do the same thing.

5
  • 1
    Terminal does know your directory. The shell reports to Apple Terminal whenever directory changes; the code that enables this is in /etc/bashrc. Commented Mar 24, 2015 at 10:30
  • 1
    That would be alias openhere='open -a /Systems/Applications/Utilities/Terminal.app .' for Big Sur OS :)
    – iulial
    Commented Mar 2, 2022 at 9:19
  • 2
    just open -a Terminal . seems to do the trick
    – Seth Tisue
    Commented Jun 30, 2022 at 3:00
  • @hamstergene, I don't see anything in my /etc/bashrc that "reports to Apple Terminal" about directory changes. Mine sets a prompt that bash itself updates, and tells bash to change its idea about Terminal directions upon process completion. Or am I missing something? Commented Jun 30, 2022 at 6:24
  • iTerm open -a iTerm .
    – Andy
    Commented Nov 2, 2023 at 8:45
5

In Zshell, I need to do both this setting

enter image description here

and I need this in my .zshrc

# http://superuser.com/a/315029/4952
# Set Apple Terminal.app to resume directory... still necessary 2018-10-26
if [[ $TERM_PROGRAM == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]] {
  function chpwd {
    local SEARCH=' '
    local REPLACE='%20'
    local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
    printf '\e]7;%s\a' "$PWD_URL"
  }
  chpwd
}

I've tried without one or the other to no avail.

You must log in to answer this question.

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