z: refresh $RANDOM's value outside subshell
This change references `$RANDOM` outside the subshell to refresh it for the
next subshell invocation. Otherwise, subsequent runs of the function get the
same value and, if run simultaneously, they may clobber each others' temp .z
files.
This is due to how zsh distributes RANDOM values when running inside a
subshell:
subshells that reference RANDOM will result in identical pseudo-random
values unless the value of RANDOM is referenced or seeded in the parent
shell in between subshell invocations
See: http://zsh.sourceforge.net/Doc/Release/Parameters.html#index-RANDOM
Diff
1diff --git a/plugins/z/z.sh b/plugins/z/z.sh
2index 4fc75dc6af295218d0872d3e96d3912f436ddf1e..5fe6d5266f8e124bfdf275bf8371e7586e049a57 100644
3--- a/plugins/z/z.sh
4+++ b/plugins/z/z.sh
5@@ -222,10 +222,16 @@ if type compctl >/dev/null 2>&1; then
6 if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
7 _z_precmd() {
8 (_z --add "${PWD:a}" &)
9+ # Reference $RANDOM to refresh its value inside the subshell
10+ # Otherwise, multiple runs get the same value
11+ : $RANDOM
12 }
13 else
14 _z_precmd() {
15 (_z --add "${PWD:A}" &)
16+ # Reference $RANDOM to refresh its value inside the subshell
17+ # Otherwise, multiple runs get the same value
18+ : $RANDOM
19 }
20 fi
21 [[ -n "${precmd_functions[(r)_z_precmd]}" ]] || {