Commit 052493b1 authored by Marc Cornellà's avatar Marc Cornellà

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
parent 851899e5
...@@ -222,10 +222,16 @@ if type compctl >/dev/null 2>&1; then ...@@ -222,10 +222,16 @@ if type compctl >/dev/null 2>&1; then
if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
_z_precmd() { _z_precmd() {
(_z --add "${PWD:a}" &) (_z --add "${PWD:a}" &)
# Reference $RANDOM to refresh its value inside the subshell
# Otherwise, multiple runs get the same value
: $RANDOM
} }
else else
_z_precmd() { _z_precmd() {
(_z --add "${PWD:A}" &) (_z --add "${PWD:A}" &)
# Reference $RANDOM to refresh its value inside the subshell
# Otherwise, multiple runs get the same value
: $RANDOM
} }
fi fi
[[ -n "${precmd_functions[(r)_z_precmd]}" ]] || { [[ -n "${precmd_functions[(r)_z_precmd]}" ]] || {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment