Skip to content

Commit

Permalink
Fix zsh stalled $RANDOM variable (rupa#247)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mcornella authored Apr 3, 2020
1 parent 6586b61 commit bbec3cb
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions z.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@ if type compctl >/dev/null 2>&1; then
if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
_z_precmd() {
(_z --add "${PWD:a}" &)
: $RANDOM
}
else
_z_precmd() {
(_z --add "${PWD:A}" &)
: $RANDOM
}
fi
[[ -n "${precmd_functions[(r)_z_precmd]}" ]] || {
Expand Down

0 comments on commit bbec3cb

Please sign in to comment.