7

I'm running a zsh non-login shell (zsh version 5.8.1) in a tab of Terminal.app under MacOS 12.6.5.

When creating interactive child-zsh processes and exit them, I see a message

Saving session...completed.

When I later enter a new zsh, with

zsh

I get a message such as

Restored session: Mon Apr 17 12:28:19 CEST 2023

I don't know what zsh is doing here behind my back, but I don't like it. My guess is that a "session" contains of zsh variables and their values, and they are somehow "restored" to a previous value.

I googled for apple shell sessions, but nothing usable came up. Could someone explain to me, what is going on here, and how I can turn this off? I have used zsh on Linux and Windows before and got used to the fact that the shell is doing just what I ask it to do, and not something fancy on its own.

1

3 Answers 3

8

The code for this is in /etc/{bashrc,zshrc}_Apple_Terminal, in the default configuration it ensures that shell history is preserved even if you have several tabs open in Terminal.

Both files include details about configuration options and also explain how to disable it as a whole.

To disable in zsh

# The save/restore mechanism as a whole can be disabled by setting an
# environment variable (typically in `${ZDOTDIR:-$HOME}/.zshenv`):
#
#   SHELL_SESSIONS_DISABLE=1

To disable in bash

# The save/restore mechanism is disabled if the following file exists:
#
#   ~/.bash_sessions_disable
0
0

You may also be interested in:

defaults write com.apple.Terminal NSQuitAlwaysKeepsWindows -bool false

To prevent windows and tabs from reappearing. If you want it to take effect for all apps use NSGlobalDomain as mentioned in an answer to How do I turn off "Close windows when quitting an app" with defaults write?.

-1

If you want to keep the session history and restauration processes without having the notifications, you can simply edit the configuration files.

See my answer here

[Adding this answer as there used to be above comments from the OP asking for exactly that]

You must log in to answer this question.

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