From 052493b1ba71fe7e13554e57571fe4c793d53c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 6 Feb 2019 11:55:38 +0100 Subject: [PATCH] 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 --- plugins/z/z.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/z/z.sh b/plugins/z/z.sh index 4fc75dc6a..5fe6d5266 100644 --- a/plugins/z/z.sh +++ b/plugins/z/z.sh @@ -222,10 +222,16 @@ if type compctl >/dev/null 2>&1; then if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then _z_precmd() { (_z --add "${PWD:a}" &) + # Reference $RANDOM to refresh its value inside the subshell + # Otherwise, multiple runs get the same value + : $RANDOM } else _z_precmd() { (_z --add "${PWD:A}" &) + # Reference $RANDOM to refresh its value inside the subshell + # Otherwise, multiple runs get the same value + : $RANDOM } fi [[ -n "${precmd_functions[(r)_z_precmd]}" ]] || {