The most complex and most real-time solution is to write a user trap function in .zshrc
which when the trapped signal is caught, sources .zshrc
itself.
Like this:
~$ cat .zshrc
trap includerc USR1
includerc() {
source $HOME/.zshrc
}
alias xxx='df'
Within zsh, this can be seen now:
zshsession> alias
which-command=whence
xxx=df
Now some change in .zshrc
~$ cat .zshrc
trap includerc USR1
includerc() {
source $HOME/.zshrc
}
alias xxx='df -g'
alias yyy='someothercommand'
Here comes the tricky part. Using inotify
watching .zshrc
or by a watcher script that examines the last modification of .zshrc
a command is triggered that sends USR1 signal to all zsh
processes of the user. Now I just ran it in another shell:
~$ ps -a | awk '$4=="zsh" {print $1}' | xargs kill -SIGUSR1
And the result is:
zshsession> alias
which-command=whence
xxx='df -g'
yyy=someothercommand
Very interesting approach. However, I'd rather use
killall -s USR1 zsh
than this ps-awk-xargs construct. – mpy – 2016-02-20T09:12:03.753Valid correction. Thx! – Gombai Sándor – 2016-02-20T09:14:45.150