#!/usr/bin/env bash # Summary: Rehash pyenv shims (run this after installing executables) set -e [ -n "$PYENV_DEBUG" ] && set -x SHIM_PATH="${PYENV_ROOT}/shims" PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.pyenv-shim" # Create the shims directory if it doesn't already exist. mkdir -p "$SHIM_PATH" # Ensure only one instance of pyenv-rehash is running at a time by # setting the shell's `noclobber` option and attempting to write to # the prototype shim file. If the file already exists, print a warning # to stderr and exit with a non-zero status. set -o noclobber { echo > "$PROTOTYPE_SHIM_PATH" } 2>/dev/null || { echo "pyenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" exit 1 } >&2 set +o noclobber # If we were able to obtain a lock, register a trap to clean up the # prototype shim when the process exits. trap remove_prototype_shim EXIT remove_prototype_shim() { rm -f "$PROTOTYPE_SHIM_PATH" } # The prototype shim file is a script that re-execs itself, passing # its filename and any arguments to `pyenv exec`. This file is # hard-linked for every binary and then removed. The linking technique # is fast, uses less disk space than unique files, and also serves as # a locking mechanism. create_prototype_shim() { cat > "$PROTOTYPE_SHIM_PATH" <