Create New Tab Sessions with the same working Directory

18,511

Solution 1

One of the options for a profile is which directory to use when creating a session with that profile. The default is to use your home directory, but you can change that to use the previous directory instead. You can change this setting in the default profile (allowing you to continue using -T), or you can create a new profile which uses this setting, and assign a different keyboard shortcut to create a session with that profile.

Solution 2

Preferences->Profiles->Working Directory->Reuse previous session's directory

Share:
18,511
StanleyZheng
Author by

StanleyZheng

Full stack developer. Always working on new projects.

Updated on June 20, 2022

Comments

  • StanleyZheng
    StanleyZheng about 2 years

    Often in workflow you are working within a directory and then need to create a second terminal or session to the same directory.

    TAB 1
    #~/home
    cd really
    #~/home/really
    cd long
    #~/home/really/long
    cd filepath
    #~/home/really/long/filepath
    node filepath
    #session now occupied 
    
    #new TAB
    #CTR + T
    #~/home
    #I want to be in the same filepath 
    

    is there a setting somewhere to do this?

  • StanleyZheng
    StanleyZheng over 10 years
    Awesome thanks! The Short Version, For Iterm2 Iterm-> Preferences-> profiles -> working directory -> Reuse Previous Session Directory
  • StanleyZheng
    StanleyZheng over 10 years
    tried this in Terminal and iTerm2 doesn't seem to work. @chepner gave a good solution for iterm2 users
  • Amrit Dhungana
    Amrit Dhungana over 10 years
    I have use oh-my-zsh too. Have you use it ? Its no T its D
  • chepner
    chepner over 10 years
    This just splits the window, with the new pane using the same profile. Whether that pane keeps the same directory depends on the profile setting.
  • Sgnl
    Sgnl over 8 years
    for more control: Iterm2 Iterm-> Preferences-> profiles -> Advanced Config [edit button] -> now you can choose a different action for panes or tabs or windows.
  • DianeZhou
    DianeZhou over 4 years
    This feature is broken in iTerm2-3.3.7(The most latest one). Is there any other solution?
  • chepner
    chepner over 4 years
    The "Reuse previous session's directory" option is still available in 3.3.8beta.
  • Darragh Enright
    Darragh Enright over 4 years
    Fantastic! I cannot believe I didn't bother looking this up before, so useful. I'm using 3.3.9 and you can specify advanced behaviour for when you open a new tab, window or split pane.
  • alper
    alper about 4 years
    Does it also work if I connected over ssh? @chepner