89

I'm using iTerm for my command line needs, and when I open a tab using Cmd ⌘ + T I want it to open the tab cd'ed to the same location as the tab that was open when I hit Cmd ⌘ + T (instead of opening in my /Users/kramer65).

I searched around the Preferences, but I can't seem to find it. Does anybody know how I can do this? All tips are welcome!

130

Select "Reuse previous session's directory" from the preferences of your profile:

Alternatively click on "Advanced Configuration" then "Edit..." so you can set the working directory separately for new windows, new tabs & new split panes

44

This is a year old, but I'd like to add a response that isn't so heavy-handed. The accepted answer will open the previous directory every time you open a new tab, which I personally find frustrating. I feel it's easier to always open in the home directory and then open the current directory in a new tab as needed.

To do that, simply run the following command:

open . -a iterm

That will open the current directory (open .) using the application (-a) that most closely matches iterm.

1
  • I wonder if you could pass a command to that new iterm using the same open syntax. Putting this inside a postactivate for a python venv you could open the iterm and have it ssh to a remote server as part of your workon workflow
    – boatcoder
    Aug 2 at 17:43
6

To bind a special keybinding to this:

  • go to Settings ( Cmd ⌘ + ,)
  • then keys
  • select the + sign
  • choose a keybinding
  • select the duplicate tab action.
0

If you've just set "Reuse previous session's directory" and the change doesn't seem to be taking effect, it's worth noting that the new changes will only apply to tabs / panes that get opened after you've chosen this setting.

For example:

  • Let's say the current setting is: "Home Directory", and you have a tab open (tab #1)
  • You go to "Preferences" and change to "Reuse previous session's directory"
  • If you open a new tab (tab #2) while on tab #1, it will still use the previous settings
  • However, if you open another tab (tab #3) while on Tab 2, it will respect the new configuration

You must log in to answer this question.

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