I want to create a script that runs when a Zsh instance starts, but only if the instance is:
I think I'm right to say
.zshrc runs for all interactive shell instances,
.zlogin run for all login shells, and
.zshenv runs in all cases.
The reason I want to do this is to check if there is an existing ssh-agent running, and make use of it in the newly opened shell if there is.
I imagine any tests carried out would be best placed in
.zshrc (as this guarantees an interactive shell) and the designated "non-login event" script called from there.
I probably first want to check if the new shell is already running as part of an existing remote SSH session before testing for the ssh-agent, but I have found this SE recipe for this purpose.
I pick Zsh as it is the shell I favor, but I imagine any correct technique to do this would apply similarly to other shells.