1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-08 11:33:49 -05:00

Compare commits

...

18 Commits

Author SHA1 Message Date
Sam Stephenson
b10bdb1e78 rbenv 0.3.0 2011-12-25 21:32:48 -05:00
Sam Stephenson
ee5ad02d42 Add --no-rehash option to rbenv-init (#170) 2011-12-25 20:59:24 -05:00
Sam Stephenson
cd2094ff71 Remove deprecated set-default and set-local commands 2011-12-25 20:39:11 -05:00
Sam Stephenson
5052a4161c Update readme screenshot to use global instead of set-default (fixes #165) 2011-12-25 16:53:59 -05:00
Sam Stephenson
7fbcde8af0 Properly expand RBENV_DIR and ensure it exists 2011-12-25 16:41:15 -05:00
Sam Stephenson
b670849ebd Merge remote-tracking branch 'mlafeldt/rbenv-rehash'
Conflicts:
	libexec/rbenv-rehash
2011-12-24 18:03:10 -05:00
Sam Stephenson
288c6b3f09 Go with paren-style function definition 2011-12-24 17:49:22 -05:00
Sam Stephenson
802d70568c Merge pull request #168 from mgrubb/topic/portability-fixes
Made ksh portability changes
2011-12-24 14:48:34 -08:00
Sam Stephenson
c4721169e3 Merge pull request #163 from richoH/features/completion_only_in_interactive_shells
Only run compctl if it's an interactive shell
2011-12-24 14:44:41 -08:00
Sam Stephenson
efe600f6de Ensure shims don't disappear when rehashed 2011-12-24 15:16:37 -05:00
Michael Grubb
7e83e07cf3 Made ksh portability changes
Added specific message for ksh in identifying the proper shell
initialization file.

Changed rbenv functiond definition to be more portable.
Shell functions should be defined by using the function command or
using the parenthesis grammar, but using both is not portable:

rbenv() {...  -or-
function rbenv { ...
2011-12-15 14:54:38 -06:00
richo
65f0be0c20 Bail on completion init if we're not an interactive shell
Based on the approach by @imajes
2011-12-11 01:57:56 +11:00
Joshua Peek
adf9c97616 Merge pull request #146 from pervel/patch-1
Quoting the argument to greadlink to make it work with paths containing spaces
2011-11-22 07:33:27 -08:00
Per Velschow
dfc7645609 Quoting the argument to greadlink to make it work with paths containing spaces. 2011-11-18 21:21:16 +01:00
Mathias Lafeldt
9dde161b65 rbenv-rehash: use $OLDPWD to restore previous working directory
$OLDPWD is a standard shell variable that contains the previous working
directory as set by the "cd" command. No need to save $PWD to some
custom variable.

(We could also have used "cd -" but it prints out $OLDPWD too.)
2011-11-14 22:30:47 +01:00
Mathias Lafeldt
0324b118ee rbenv-rehash: remove superfluous trap signals
A trap on the special signal EXIT is executed before the shell
terminates. EXIT actually covers SIGINT and SIGTERM as well, and
we don't need any extra traps for them.

See bash(1) and "help trap" in bash.
2011-11-14 22:30:47 +01:00
Sam Stephenson
4cc6665d0a Zsh users need to modify ~/.zshenv, not ~/.zshrc 2011-11-14 12:52:10 -06:00
Joshua Peek
be7dcc0ad8 Add rbenv root
Prints $RBENV_ROOT (defaults to ~/.rbenv)
2011-11-10 10:54:30 -06:00
9 changed files with 154 additions and 41 deletions

View File

@@ -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
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…_
@@ -100,13 +100,13 @@ easy to fork and contribute any changes back upstream.
$ 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.
$ 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
begin using rbenv.
@@ -314,6 +314,24 @@ tracker](https://github.com/sstephenson/rbenv/issues).
### <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)
* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an

View File

@@ -1,3 +1,7 @@
if [[ ! -o interactive ]]; then
return
fi
compctl -K _rbenv rbenv
_rbenv() {

View File

@@ -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
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…_
@@ -81,13 +81,13 @@ easy to fork and contribute any changes back upstream.
$ 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.
$ 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
begin using rbenv.
@@ -295,6 +295,24 @@ tracker](https://github.com/sstephenson/rbenv/issues).
### 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)
* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an

View File

@@ -3,7 +3,7 @@ set -e
[ -n "$RBENV_DEBUG" ] && set -x
resolve_link() {
$(type -p greadlink readlink | head -1) $1
$(type -p greadlink readlink | head -1) "$1"
}
abs_dirname() {
@@ -30,7 +30,12 @@ export RBENV_ROOT
if [ -z "${RBENV_DIR}" ]; then
RBENV_DIR="$(pwd)"
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
export RBENV_DIR
@@ -55,7 +60,7 @@ shopt -u nullglob
command="$1"
case "$command" in
"" | "-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)"

View File

@@ -8,6 +8,12 @@ if [ "$1" = "-" ]; then
shift
fi
no_rehash=""
if [ "$1" = "--no-rehash" ]; then
no_rehash=1
shift
fi
shell="$1"
if [ -z "$shell" ]; then
shell="$(basename "$SHELL")"
@@ -41,6 +47,9 @@ if [ -z "$print" ]; then
zsh )
profile='~/.zshrc'
;;
ksh )
profile='~/.profile'
;;
* )
profile='your profile'
;;
@@ -66,12 +75,14 @@ bash | zsh )
;;
esac
echo 'rbenv rehash 2>/dev/null'
if [ -z "$no_rehash" ]; then
echo 'rbenv rehash 2>/dev/null'
fi
commands=(`rbenv commands --sh`)
IFS="|"
cat <<EOS
function rbenv() {
rbenv() {
command="\$1"
if [ "\$#" -gt 0 ]; then
shift

View File

@@ -22,7 +22,7 @@ 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 SIGINT SIGTERM EXIT
trap remove_prototype_shim EXIT
remove_prototype_shim() {
rm -f "$PROTOTYPE_SHIM_PATH"
@@ -43,33 +43,106 @@ SH
chmod +x "$PROTOTYPE_SHIM_PATH"
}
# Make shims by iterating over every filename argument and creating a
# hard link from the prototype shim to a file of the same name in the
# shims directory, if one does not already exist.
# 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.
make_shims() {
local glob="$@"
local shims="$@"
for file in $glob; do
for file in $shims; do
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"
done
}
# Save the working directory.
CUR_PATH=$PWD
# Once the registered shims have been installed, we make a second pass
# 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"
# 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
shopt -s nullglob
make_shims ../versions/*/bin/*
# Restore the previous working directory.
cd "$CUR_PATH"
cd "$OLDPWD"
# Allow plugins to register shims.
for script in $(rbenv-hooks rehash); do
source "$script"
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
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
echo $RBENV_ROOT

View File

@@ -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 "$@"

View File

@@ -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 "$@"