reload all running zsh instances

I typically have on the order of a dozen zsh processes running. When I edit my config files, I'd like a clean way to get them all to re-initialize. Ideally, this would not mean completely killing them all and restarting as that loses my working directory, any shell variables I had set locally, temporary aliases, etc. In a given shell, I can exec "${SHELL}" and that works fine, but I want a way to force all active zsh instances under my login to do that.


You can define a trap function:

TRAPUSR1() {
  if [[ -o INTERACTIVE ]]; then
     {echo; echo execute a new shell instance } 1>&2
     exec "${SHELL}"
  fi
}

This funtion is called when the running shell catches a USR1 signal, initiated by kill -USR1 <PID>. It checks if the running zsh instance is interactive and if so, replaces it with a new one.+

So, to update all your running zsh interactive session in one run, simply use

killall -USR1 zsh

But please be aware that if you have running zsh instances without the TRAPUSR1() function defined, these will exit upon USR1! That's why you should define the trap in /etc/zshenv, as this is the only file which is read by every zsh instance,+ including scripts and sessions started with zsh -f.


+ Credits go to @Adaephon, who pointed this out in a comment.