Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [RFC][PATCH] Add zrestart()

On Sun, May 9, 2021 at 2:00 PM Lawrence Velázquez <larryv@xxxxxxx> wrote:
> Anything else on this?

There's really no ideal solution for this.  The only "good" way to
handle it is to have two different windows/terminals/whatever from
which to log in, so you can leave the old shell running while you test
whether a fresh login works properly.

Given we can't assure that, a scheme that occurs to me, but might be
tricky to make work smoothly:

At the beginning of $HOME/.zshenv, check for existence of a
$HOME/.zsh-safe file (exact name TBD).
If that file exists, set ZDOTDIR to something
innocuous/nonexistent/freshly-created, and print a message telling the
user he needs to repair his startup files and try again.  Sleep for a
few seconds and then return from .zshenv.
If the file does not exist, create it, and print a message advising
the user that if a shell prompt is reached, to remove the file and
also remove the test code from $HOME/.zshenv.  Sleep for a few seconds
and then go on with whatever else is in ~/.zshenv.

It's then safe to use "exec zsh" (or "exec zsh -l" if the shell is
already a login shell) because even if the user is kicked all the way
out of his remote session, he'll be able to log back in under the
"safe mode" created in ~/.zshenv and try again.

zrestart should thus unset ZDOTDIR, insert the test code into
~/.zshenv, and remove the .zsh-safe file.

Various details that might also be considered:

When creating the file, set up a precmd hook that cleans up the above
and unhooks itself, so the user doesn't have to do anything.  This
could be clobbered by later code, though, so printing the instructions
is probably still useful.

Do some or all of this only if .zshenv is run from an interactive shell.

There's no way to prevent /etc/zshenv from foiling all of this, e.g.,
by setting ZDOTDIR.

Messages sorted by: Reverse Date, Date, Thread, Author