138

Can I save tabs on exit in my iTerm 2, so I don't have to open same directories again after restart?

Like Chrome does, for example.

I couldn't find such option in settings. Maybe "Arrangements" is what I want, but it seems that it requires me to explicitly save tabs.

  • iTerm 2 will open your saved Window Arrangements if you need that and don't like iTerm or Terminal.app on Lion. It works on Snow Leopard as well. – bmike Aug 18 '11 at 19:40
  • ouch, I had no idea that iTerm 2 is something different from iTerm. I used iTerm 2. Can it save Window Arrangement on exit? I couldn't find out how – valya Aug 18 '11 at 20:03
  • 1
    You have to explicitly save the settings from my brief read of the FAQ - we'll see if anyone here knows for sure now that the question is razor sharp :-) Nice edits. – bmike Aug 18 '11 at 20:05
  • 1
    iTerm2 has no support for reopening directories. This ticket can be used to track the implementation: code.google.com/p/iterm2/issues/detail?id=2775 – Jörn Zaefferer Sep 16 '14 at 22:00
  • It's a nightmare, but really useful once you set it up. I documented the full process in a blog post which is too long to post on StackOverflow. – Andy Ray Jun 6 '17 at 22:37

12 Answers 12

125

You can Save and Restore Window Arrangement with ⇧ ⌘ S and ⇧ ⌘ R options under the Window screen in iTerm2

You can start the default Arrangement Option to enable are at Preferences -> General -> Startup -> Open default window arrangement .

You can add arrangements with the ⇧ ⌘ S and manage them under Preferences -> Arrangements tab .

iTerm Window Options

  • 2
    the one detail that was important for me here: first arrange windows like you want to have them, then hit ⇧⌘s and save as 'Default' (without the quotes, capitalized). the exact spelling is also shown on the Window > Restore Window Arrangement submenu. any other spelling will save the arrangement alright but not restore it on iTerm restart. – flow Oct 20 '13 at 13:52
  • 14
    This does not answer the original question of "Can I save tabs on exit in my iTerm 2, so I don't have to open same directories again after restart?" – Jeremy Jul 15 '14 at 17:56
  • @JeremyLee Indeed. One will have to couple Window Arrangement with profile arrangement, like mentioned by Rob below, to achieve this purpose. – xji Feb 1 '15 at 8:07
  • This doesn't do what Chrome does, it seems. Chrome re-opens the tabs that were open when you last quit it. This seems to be more like something Internet Explorer did ages ago, where you could tell what it should open every time you start it, regardless of what was open last time. – Daniel C. Sobral Jul 7 '16 at 21:06
  • @flow You can also go to the arrangements tab in preferences, select a given arrangement and click 'set default' in the lower left hand side of the screen – Adam Tolley Oct 13 '17 at 15:18
20

Try iTermocil

iTermocil allows you to setup pre-configured layouts of windows and panes in iTerm2, having each open in a specified directory and execute specified commands.

  • Can it also preserve tabs and the working directories of the different tabs (as asked in the question)? – nohillside Nov 3 '15 at 7:59
  • @patrix yes, it has to be set in yml file, however this does not restore tabs on iTerm restart – forloop Nov 4 '15 at 9:36
  • This is exactly what I needed! – dhempler Jul 22 '17 at 13:44
10

Here's what I do, running OSX 10.10.4:

Install iTerm nightly (the latest release). Brew is the easiest:

brew tap caskroom/versions && brew cask install iterm2-nightly

You can run this side-by-side with other versions; I use Spotlight and look at the versions to see which one I'm opening. By default it will be set to enable session restore which will restore tabs and directories. However, you may have to adjust your Apple system preferences in System Prefs>General where Close windows when quitting an app. See this Gitlab issue for a screenshot if that confuses you.

  • This is a new feature in at least iTerm 2.9.20150626 beta. They elsewhere confusingly refer to it as part of the iTerm2 version 3 beta. Anyway, automatic session restore rocks! – Bluu Aug 21 '15 at 18:22
  • As new as this answer is, it seems that there is currently no iterm2-nightly Homebrew cask. – David Resnick Aug 24 '15 at 11:43
  • 1
    Thanks David - I updated it to refer to github.com/caskroom/homebrew-versions – Ben Creasy Aug 24 '15 at 16:44
6
  1. In iTerm go to Preferences -> General and under Startup set Use System Window Restoration Setting. enter image description here

  2. Go to macOS System Preferences -> General and make sure that Close windows when quitting an app is unchecked. enter image description here

4

If someone like me is having trouble enabling 'Session Restoration' in iTerm 2.9 beta (or iTerm3 beta how they call it) do next:

  1. Open preferences
  2. General tab
  3. Startup
  4. Change to 'Use System window restoration setting'. Restart.

enter image description here

Probably for tech geeks it's obvious that one should select this option for this feature to work but for me it was not and I have never seen this mentioned anywhere.

4

This is possible with iterm2: https://www.iterm2.com/documentation-restoration.html

You can toggle this feature with Prefs>Advanced>Enable session restoration, but you must restart iTerm2 after changing this setting.

I also had to uncheck "close windows when quitting an app" in my General system preferences: https://support.apple.com/en-us/HT204005.

3

Coming in quite late, but you should first create some profiles and then use Command - Option/Alt - Shift H (H is for horizontal split; or swap in V for vertical split). It will show you a list of your profiles and you can then add those to your split. Once you build the setup you like just like Sairam did above.

Here's a vid explaining: iterm2 Profiles and Window Arrangements.

3

It's still not exactly what you want, but since you can check the $ITERM_SESSION_ID environment variable to see which panel you are in, by combining this with a saved window arrangement, you can have each of your panel to start with different initial path, or just anything you would like to run by default.

For example, my saved windows arrangment is two tabs with two panels in the first tab. So I will have $ITERM_SESSION_ID=w0t0p0 for the first panel in the first tab, $ITERM_SESSION_ID=w0t0p1 for the 2nd panel, and $ITERM_SESSION_ID=w0t1p0 for the single panel in the 2nd tab. 'w' stands for window, 't' for tab, and 'p' for panel. I check these variables in my .zshrc, and run Vim in the w0t0p0, iPython in the w0t1p0, respectively.

3

In iTerm2 v2.1.4 there's a setting under Profiles: Reuse previous session's directory. It may have been there in the earlier versions, but I haven't looked.

See screenshot:

Screenshot

2

No, as of today I couldn't find any way to set a layout/tabs with paths and recover it (as Sublime Text does for example) in iTerm (2.9).

Personally, I'm astonished on how a basic feature (I think much more relevant than tabs colours, for example) is still missing on such a mature project.

1

Disabling the System Preferences -> General -> "Close windows when quitting an app" checkbox did the job for me.

-1

I found the solution in iTerm2's official website, check it out here https://www.iterm2.com/documentation-restoration.html.

After setting iTerm2 restores last session just like Chrome. However the process(e.g. npm start) can not be restored.

Works perfectly under iTerm2 build 3.0.14 and macOS Sierra 10.12.6 (16G29). Hope it helps.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

You must log in to answer this question.

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