Skip to content

Commit

Permalink
Workaround for scripts in $PATH which needs to be source'd (pyenv#100
Browse files Browse the repository at this point in the history
…, pyenv#688)
  • Loading branch information
yyuu committed Jul 20, 2017
1 parent 0314de0 commit 52d6acc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pyenv.d/rehash/source.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
PROTOTYPE_SOURCE_SHIM_PATH="${SHIM_PATH}/.pyenv-source-shim"

shims=()
for shim in $(cat "${BASH_SOURCE%/*}/source.txt"); do
if [ -n "${shim%%#*}" ]; then
shims[${#shims[*]}]="${shim})return 0;;"
fi
done
eval "source_shim(){ case \"\$1\" in ${shims[@]} *)return 1;;esac;}"

cat > "${PROTOTYPE_SOURCE_SHIM_PATH}" <<SH
#!/usr/bin/env bash
[ -n "\$PYENV_DEBUG" ] && set -x
export PYENV_ROOT="${PYENV_ROOT}"
program="\$("$(command -v pyenv)" which "\${BASH_SOURCE##*/}")"
if [ -e "\${program}" ]; then
. "\${program}" "\$@"
fi
SH
chmod +x "${PROTOTYPE_SOURCE_SHIM_PATH}"

shopt -s nullglob
for shim in "${SHIM_PATH}/"*; do
if source_shim "${shim}"; then
cp "${PROTOTYPE_SOURCE_SHIM_PATH}" "${shim}"
fi
done
shopt -u nullglob

rm -f "${PROTOTYPE_SOURCE_SHIM_PATH}"
1 change: 1 addition & 0 deletions pyenv.d/rehash/source.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gettext.sh

0 comments on commit 52d6acc

Please sign in to comment.