mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Merge pull request #299 from sstephenson/automatic-local-exec
Automatic local exec
This commit is contained in:
commit
e0b8938fef
2 changed files with 45 additions and 10 deletions
|
@ -37,12 +37,41 @@ create_prototype_shim() {
|
|||
cat > "$PROTOTYPE_SHIM_PATH" <<SH
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
[ -n "\$RBENV_DEBUG" ] && set -x
|
||||
|
||||
program="\${0##*/}"
|
||||
if [ "\$program" = "ruby" ]; then
|
||||
for arg; do
|
||||
case "\$arg" in
|
||||
-e* | -- ) break ;;
|
||||
*/* )
|
||||
if [ -f "\$arg" ]; then
|
||||
export RBENV_DIR="\${arg%/*}"
|
||||
break
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
export RBENV_ROOT="$RBENV_ROOT"
|
||||
exec rbenv exec "\${0##*/}" "\$@"
|
||||
exec rbenv exec "\$program" "\$@"
|
||||
SH
|
||||
chmod +x "$PROTOTYPE_SHIM_PATH"
|
||||
}
|
||||
|
||||
# If the contents of the prototype shim file differ from the contents
|
||||
# of the first shim in the shims directory, assume rbenv has been
|
||||
# upgraded and the existing shims need to be removed.
|
||||
remove_outdated_shims() {
|
||||
for shim in *; do
|
||||
if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then
|
||||
for shim in *; do rm -f "$shim"; done
|
||||
fi
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
# The basename of each argument passed to `make_shims` will be
|
||||
# registered for installation as a shim. In this way, plugins may call
|
||||
# `make_shims` with a glob to register many shims at once.
|
||||
|
@ -97,10 +126,11 @@ remove_stale_shims() {
|
|||
|
||||
# Change to the shims directory.
|
||||
cd "$SHIM_PATH"
|
||||
shopt -s nullglob
|
||||
|
||||
# Create the prototype shim, then register shims for all known binaries.
|
||||
create_prototype_shim
|
||||
shopt -s nullglob
|
||||
remove_outdated_shims
|
||||
make_shims ../versions/*/bin/*
|
||||
|
||||
# Restore the previous working directory.
|
||||
|
|
|
@ -2,14 +2,19 @@
|
|||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
root="$RBENV_DIR"
|
||||
while [ -n "$root" ]; do
|
||||
if [ -e "${root}/.rbenv-version" ]; then
|
||||
echo "${root}/.rbenv-version"
|
||||
exit
|
||||
fi
|
||||
root="${root%/*}"
|
||||
done
|
||||
find_local_version_file() {
|
||||
local root="$1"
|
||||
while [ -n "$root" ]; do
|
||||
if [ -e "${root}/.rbenv-version" ]; then
|
||||
echo "${root}/.rbenv-version"
|
||||
exit
|
||||
fi
|
||||
root="${root%/*}"
|
||||
done
|
||||
}
|
||||
|
||||
find_local_version_file "$RBENV_DIR"
|
||||
[ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD"
|
||||
|
||||
global_version_file="${RBENV_ROOT}/version"
|
||||
|
||||
|
|
Loading…
Reference in a new issue