mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-08 19:43:48 -05:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b10bdb1e78 | ||
|
|
ee5ad02d42 | ||
|
|
cd2094ff71 | ||
|
|
5052a4161c | ||
|
|
7fbcde8af0 | ||
|
|
b670849ebd | ||
|
|
288c6b3f09 | ||
|
|
802d70568c | ||
|
|
c4721169e3 | ||
|
|
efe600f6de | ||
|
|
7e83e07cf3 | ||
|
|
65f0be0c20 | ||
|
|
adf9c97616 | ||
|
|
dfc7645609 | ||
|
|
9dde161b65 | ||
|
|
0324b118ee | ||
|
|
4cc6665d0a | ||
|
|
be7dcc0ad8 |
24
README.md
24
README.md
@@ -4,7 +4,7 @@ rbenv lets you easily switch between multiple versions of Ruby. It's
|
|||||||
simple, unobtrusive, and follows the UNIX tradition of single-purpose
|
simple, unobtrusive, and follows the UNIX tradition of single-purpose
|
||||||
tools that do one thing well.
|
tools that do one thing well.
|
||||||
|
|
||||||
<img src="http://i.sstephenson.us/rbenv.png" width="894" height="464">
|
<img src="http://i.sstephenson.us/rbenv2.png" width="894" height="464">
|
||||||
|
|
||||||
### rbenv _does…_
|
### rbenv _does…_
|
||||||
|
|
||||||
@@ -100,13 +100,13 @@ easy to fork and contribute any changes back upstream.
|
|||||||
|
|
||||||
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
|
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
|
||||||
|
|
||||||
**Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`.
|
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
|
||||||
|
|
||||||
3. Add rbenv init to your shell to enable shims and autocompletion.
|
3. Add rbenv init to your shell to enable shims and autocompletion.
|
||||||
|
|
||||||
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
|
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
|
||||||
|
|
||||||
**Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`.
|
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
|
||||||
|
|
||||||
4. Restart your shell so the path changes take effect. You can now
|
4. Restart your shell so the path changes take effect. You can now
|
||||||
begin using rbenv.
|
begin using rbenv.
|
||||||
@@ -314,6 +314,24 @@ tracker](https://github.com/sstephenson/rbenv/issues).
|
|||||||
|
|
||||||
### <a name="section_4.1"></a> 4.1 Version History
|
### <a name="section_4.1"></a> 4.1 Version History
|
||||||
|
|
||||||
|
**0.3.0** (December 25, 2011)
|
||||||
|
|
||||||
|
* Added an `rbenv root` command which prints the value of
|
||||||
|
`$RBENV_ROOT`, or the default root directory if it's unset.
|
||||||
|
* Clarified Zsh installation instructions in the readme.
|
||||||
|
* Removed some redundant code in `rbenv rehash`.
|
||||||
|
* Fixed an issue with calling `readlink` for paths with spaces.
|
||||||
|
* Changed Zsh initialization code to install completion hooks only for
|
||||||
|
interactive shells.
|
||||||
|
* Added preliminary support for ksh.
|
||||||
|
* `rbenv rehash` creates or removes shims only when necessary instead
|
||||||
|
of removing and re-creating all shims on each invocation.
|
||||||
|
* Fixed that `RBENV_DIR`, when specified, would be incorrectly
|
||||||
|
expanded to its parent directory.
|
||||||
|
* Removed the deprecated `set-default` and `set-local` commands.
|
||||||
|
* Added a `--no-rehash` option to `rbenv init` for skipping the
|
||||||
|
automatic rehash when opening a new shell.
|
||||||
|
|
||||||
**0.2.1** (October 1, 2011)
|
**0.2.1** (October 1, 2011)
|
||||||
|
|
||||||
* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an
|
* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
if [[ ! -o interactive ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
compctl -K _rbenv rbenv
|
compctl -K _rbenv rbenv
|
||||||
|
|
||||||
_rbenv() {
|
_rbenv() {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ rbenv lets you easily switch between multiple versions of Ruby. It's
|
|||||||
simple, unobtrusive, and follows the UNIX tradition of single-purpose
|
simple, unobtrusive, and follows the UNIX tradition of single-purpose
|
||||||
tools that do one thing well.
|
tools that do one thing well.
|
||||||
|
|
||||||
<img src="http://i.sstephenson.us/rbenv.png" width="894" height="464">
|
<img src="http://i.sstephenson.us/rbenv2.png" width="894" height="464">
|
||||||
|
|
||||||
### rbenv _does…_
|
### rbenv _does…_
|
||||||
|
|
||||||
@@ -81,13 +81,13 @@ easy to fork and contribute any changes back upstream.
|
|||||||
|
|
||||||
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
|
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
|
||||||
|
|
||||||
**Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`.
|
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
|
||||||
|
|
||||||
3. Add rbenv init to your shell to enable shims and autocompletion.
|
3. Add rbenv init to your shell to enable shims and autocompletion.
|
||||||
|
|
||||||
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
|
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
|
||||||
|
|
||||||
**Zsh note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`.
|
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
|
||||||
|
|
||||||
4. Restart your shell so the path changes take effect. You can now
|
4. Restart your shell so the path changes take effect. You can now
|
||||||
begin using rbenv.
|
begin using rbenv.
|
||||||
@@ -295,6 +295,24 @@ tracker](https://github.com/sstephenson/rbenv/issues).
|
|||||||
|
|
||||||
### Version History ###
|
### Version History ###
|
||||||
|
|
||||||
|
**0.3.0** (December 25, 2011)
|
||||||
|
|
||||||
|
* Added an `rbenv root` command which prints the value of
|
||||||
|
`$RBENV_ROOT`, or the default root directory if it's unset.
|
||||||
|
* Clarified Zsh installation instructions in the readme.
|
||||||
|
* Removed some redundant code in `rbenv rehash`.
|
||||||
|
* Fixed an issue with calling `readlink` for paths with spaces.
|
||||||
|
* Changed Zsh initialization code to install completion hooks only for
|
||||||
|
interactive shells.
|
||||||
|
* Added preliminary support for ksh.
|
||||||
|
* `rbenv rehash` creates or removes shims only when necessary instead
|
||||||
|
of removing and re-creating all shims on each invocation.
|
||||||
|
* Fixed that `RBENV_DIR`, when specified, would be incorrectly
|
||||||
|
expanded to its parent directory.
|
||||||
|
* Removed the deprecated `set-default` and `set-local` commands.
|
||||||
|
* Added a `--no-rehash` option to `rbenv init` for skipping the
|
||||||
|
automatic rehash when opening a new shell.
|
||||||
|
|
||||||
**0.2.1** (October 1, 2011)
|
**0.2.1** (October 1, 2011)
|
||||||
|
|
||||||
* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an
|
* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ set -e
|
|||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
resolve_link() {
|
resolve_link() {
|
||||||
$(type -p greadlink readlink | head -1) $1
|
$(type -p greadlink readlink | head -1) "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
abs_dirname() {
|
abs_dirname() {
|
||||||
@@ -30,7 +30,12 @@ export RBENV_ROOT
|
|||||||
if [ -z "${RBENV_DIR}" ]; then
|
if [ -z "${RBENV_DIR}" ]; then
|
||||||
RBENV_DIR="$(pwd)"
|
RBENV_DIR="$(pwd)"
|
||||||
else
|
else
|
||||||
RBENV_DIR="$(abs_dirname "$RBENV_DIR")"
|
cd "$RBENV_DIR" 2>/dev/null || {
|
||||||
|
echo "rbenv: cannot change working directory to \`$RBENV_DIR'"
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
RBENV_DIR="$(pwd)"
|
||||||
|
cd "$OLDPWD"
|
||||||
fi
|
fi
|
||||||
export RBENV_DIR
|
export RBENV_DIR
|
||||||
|
|
||||||
@@ -55,7 +60,7 @@ shopt -u nullglob
|
|||||||
command="$1"
|
command="$1"
|
||||||
case "$command" in
|
case "$command" in
|
||||||
"" | "-h" | "--help" )
|
"" | "-h" | "--help" )
|
||||||
echo -e "rbenv 0.2.1\n$(rbenv-help)" >&2
|
echo -e "rbenv 0.3.0\n$(rbenv-help)" >&2
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
command_path="$(command -v "rbenv-$command" || true)"
|
command_path="$(command -v "rbenv-$command" || true)"
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ if [ "$1" = "-" ]; then
|
|||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
no_rehash=""
|
||||||
|
if [ "$1" = "--no-rehash" ]; then
|
||||||
|
no_rehash=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
shell="$1"
|
shell="$1"
|
||||||
if [ -z "$shell" ]; then
|
if [ -z "$shell" ]; then
|
||||||
shell="$(basename "$SHELL")"
|
shell="$(basename "$SHELL")"
|
||||||
@@ -41,6 +47,9 @@ if [ -z "$print" ]; then
|
|||||||
zsh )
|
zsh )
|
||||||
profile='~/.zshrc'
|
profile='~/.zshrc'
|
||||||
;;
|
;;
|
||||||
|
ksh )
|
||||||
|
profile='~/.profile'
|
||||||
|
;;
|
||||||
* )
|
* )
|
||||||
profile='your profile'
|
profile='your profile'
|
||||||
;;
|
;;
|
||||||
@@ -66,12 +75,14 @@ bash | zsh )
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo 'rbenv rehash 2>/dev/null'
|
if [ -z "$no_rehash" ]; then
|
||||||
|
echo 'rbenv rehash 2>/dev/null'
|
||||||
|
fi
|
||||||
|
|
||||||
commands=(`rbenv commands --sh`)
|
commands=(`rbenv commands --sh`)
|
||||||
IFS="|"
|
IFS="|"
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
function rbenv() {
|
rbenv() {
|
||||||
command="\$1"
|
command="\$1"
|
||||||
if [ "\$#" -gt 0 ]; then
|
if [ "\$#" -gt 0 ]; then
|
||||||
shift
|
shift
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ set +o noclobber
|
|||||||
|
|
||||||
# If we were able to obtain a lock, register a trap to clean up the
|
# If we were able to obtain a lock, register a trap to clean up the
|
||||||
# prototype shim when the process exits.
|
# prototype shim when the process exits.
|
||||||
trap remove_prototype_shim SIGINT SIGTERM EXIT
|
trap remove_prototype_shim EXIT
|
||||||
|
|
||||||
remove_prototype_shim() {
|
remove_prototype_shim() {
|
||||||
rm -f "$PROTOTYPE_SHIM_PATH"
|
rm -f "$PROTOTYPE_SHIM_PATH"
|
||||||
@@ -43,33 +43,106 @@ SH
|
|||||||
chmod +x "$PROTOTYPE_SHIM_PATH"
|
chmod +x "$PROTOTYPE_SHIM_PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Make shims by iterating over every filename argument and creating a
|
# The basename of each argument passed to `make_shims` will be
|
||||||
# hard link from the prototype shim to a file of the same name in the
|
# registered for installation as a shim. In this way, plugins may call
|
||||||
# shims directory, if one does not already exist.
|
# `make_shims` with a glob to register many shims at once.
|
||||||
make_shims() {
|
make_shims() {
|
||||||
local glob="$@"
|
local shims="$@"
|
||||||
|
|
||||||
for file in $glob; do
|
for file in $shims; do
|
||||||
local shim="${file##*/}"
|
local shim="${file##*/}"
|
||||||
|
register_shim "$shim"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create an empty array for the list of registered shims.
|
||||||
|
registered_shims=()
|
||||||
|
|
||||||
|
# We will keep track of shims registered for installation with the
|
||||||
|
# global `reigstered_shims` array and with a global variable for each
|
||||||
|
# shim. The array will let us iterate over all registered shims. The
|
||||||
|
# global variables will let us quickly check whether a shim with the
|
||||||
|
# given name has been registered or not.
|
||||||
|
register_shim() {
|
||||||
|
local shim="$@"
|
||||||
|
local var="$(shim_variable_name "$shim")"
|
||||||
|
|
||||||
|
if [ -z "${!var}" ]; then
|
||||||
|
registered_shims[${#registered_shims[*]}]="$shim"
|
||||||
|
eval "${var}=1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# To compute the global variable name for a given shim we must first
|
||||||
|
# escape any non-alphanumeric characters. If the shim name is
|
||||||
|
# alphanumeric (including a hyphen or underscore) we can take a
|
||||||
|
# shorter path. Otherwise, we must iterate over each character and
|
||||||
|
# escape the non-alphanumeric ones using `printf`.
|
||||||
|
shim_variable_name() {
|
||||||
|
local shim="$1"
|
||||||
|
local result="_shim_"
|
||||||
|
|
||||||
|
if [[ ! "$shim" =~ [^[:alnum:]_-] ]]; then
|
||||||
|
shim="${shim//_/_5f}"
|
||||||
|
shim="${shim//-/_2d}"
|
||||||
|
result+="$shim"
|
||||||
|
else
|
||||||
|
local length="${#shim}"
|
||||||
|
local char i
|
||||||
|
|
||||||
|
for ((i=0; i<length; i++)); do
|
||||||
|
char="${shim:$i:1}"
|
||||||
|
if [[ "$char" =~ [[:alnum:]] ]]; then
|
||||||
|
result+="$char"
|
||||||
|
else
|
||||||
|
result+="$(printf "_%02x" \'"$char")"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$result"
|
||||||
|
}
|
||||||
|
|
||||||
|
# To install all the registered shims, we iterate over the
|
||||||
|
# `registered_shims` array and create a link if one does not already
|
||||||
|
# exist.
|
||||||
|
install_registered_shims() {
|
||||||
|
for shim in "${registered_shims[@]}"; do
|
||||||
[ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
|
[ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Save the working directory.
|
# Once the registered shims have been installed, we make a second pass
|
||||||
CUR_PATH=$PWD
|
# over the contents of the shims directory. Any file that is present
|
||||||
|
# in the directory but has not been registered as a shim should be
|
||||||
|
# removed.
|
||||||
|
remove_stale_shims() {
|
||||||
|
local var
|
||||||
|
for shim in *; do
|
||||||
|
var="$(shim_variable_name "$shim")"
|
||||||
|
[ -z "${!var}" ] && rm -f "$shim"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Empty out the shims directory and make it the working directory.
|
|
||||||
rm -f "$SHIM_PATH"/*
|
# Change to the shims directory.
|
||||||
cd "$SHIM_PATH"
|
cd "$SHIM_PATH"
|
||||||
|
|
||||||
# Create the prototype shim, then make shims for all known binaries.
|
# Create the prototype shim, then register shims for all known binaries.
|
||||||
create_prototype_shim
|
create_prototype_shim
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
make_shims ../versions/*/bin/*
|
make_shims ../versions/*/bin/*
|
||||||
|
|
||||||
# Restore the previous working directory.
|
# Restore the previous working directory.
|
||||||
cd "$CUR_PATH"
|
cd "$OLDPWD"
|
||||||
|
|
||||||
|
# Allow plugins to register shims.
|
||||||
for script in $(rbenv-hooks rehash); do
|
for script in $(rbenv-hooks rehash); do
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Change back to the shims directory to install the registered shims
|
||||||
|
# and remove stale shims.
|
||||||
|
cd "$SHIM_PATH"
|
||||||
|
install_registered_shims
|
||||||
|
remove_stale_shims
|
||||||
|
|||||||
2
libexec/rbenv-root
Executable file
2
libexec/rbenv-root
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
echo $RBENV_ROOT
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
{ echo "rbenv: warning: \`set-default' has been renamed to \`global'"
|
|
||||||
echo " and will be removed in v0.3.0"
|
|
||||||
echo
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
exec rbenv-global "$@"
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
{ echo "rbenv: warning: \`set-local' has been renamed to \`local'"
|
|
||||||
echo " and will be removed in v0.3.0"
|
|
||||||
echo
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
exec rbenv-local "$@"
|
|
||||||
Reference in New Issue
Block a user