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

Compare commits

...

96 Commits

Author SHA1 Message Date
Sam Stephenson
9375e99f92 rbenv 0.4.0 2013-01-04 12:27:26 -06:00
Sam Stephenson
b66eeaf2f7 Link up the "Why choose rbenv?" wiki page 2013-01-04 12:25:00 -06:00
Mislav Marohnić
c6855e01a9 zshenv -> zshrc. update Ubuntu/zsh installation notices 2013-01-04 17:58:38 +01:00
Sam Stephenson
7f975a37f9 Deprecate ruby-local-exec 2013-01-04 10:12:29 -06:00
Sam Stephenson
41cfa5f3d0 Link to the binstubs wiki page 2013-01-04 09:19:18 -06:00
Sam Stephenson
9c45206c28 Remove unused doc directory 2013-01-03 21:22:17 -06:00
Sam Stephenson
308aa42b67 Rewrite "How It Works" with @trevorturk 2013-01-03 21:18:05 -06:00
Sam Stephenson
5174d14d5c It's all about the apps 2013-01-03 12:49:03 -06:00
Sam Stephenson
6fe338e563 New tagline 2013-01-03 12:40:54 -06:00
Sam Stephenson
266d896871 Prioritize rbenv local over rbenv global and rbenv shell 2013-01-03 10:40:28 -06:00
Sam Stephenson
7e85ae7bd2 "Usage" -> "Command Reference" 2013-01-03 10:25:31 -06:00
Sam Stephenson
9a284a3da4 Update the uninstallation section 2013-01-03 10:20:52 -06:00
Sam Stephenson
871f0e26df Tone down the RVM incompatibility notice 2013-01-03 10:09:22 -06:00
Sam Stephenson
e56885f4c9 "binary" -> "executable" 2013-01-03 10:06:12 -06:00
Sam Stephenson
149f4b4607 "per-project" -> "application-specific" 2013-01-03 10:00:10 -06:00
Sam Stephenson
80750f730f Merge pull request #302 from sstephenson/ruby-version
Support for .ruby-version files
2013-01-03 07:32:02 -08:00
Jeremy Kemper
253f6ee1d9 -information in readme pitch 2013-01-02 19:01:47 -07:00
Jeremy Kemper
bac149e824 Riff on the readme pitch 2013-01-02 19:00:04 -07:00
Sam Stephenson
3ec34448fa Rewrite the readme pitch 2013-01-02 18:56:33 -06:00
Sam Stephenson
919c4240fc Clarify that .rbenv-version is removed when migrating 2013-01-02 12:51:47 -06:00
Sam Stephenson
44c2378f2a Shims include the full path to rbenv
This makes it possible to execute rbenv shims without rbenv's bin
directory in the path.
2013-01-01 13:27:39 -06:00
Sam Stephenson
377b176260 Document .ruby-version 2012-12-31 09:58:28 -06:00
Sam Stephenson
d2a8ca7d89 Tweak the ruby- prefix warning 2012-12-31 09:58:10 -06:00
Sam Stephenson
d4faae187a Read both .ruby-version and .rbenv-version, but write (and migrate to) .ruby-version 2012-12-30 21:20:29 -06:00
Sam Stephenson
5e52fae7c1 Accept "ruby-" version prefix but print a warning to stderr 2012-12-30 19:01:30 -06:00
Sam Stephenson
b974bf54dc Prefer .ruby-version to .rbenv-version for reading local versions 2012-12-30 18:35:20 -06:00
Sam Stephenson
4b6c91e827 Usage consistency 2012-12-30 16:00:53 -06:00
Sam Stephenson
51467dc4a3 Include install and uninstall in help if ruby-build is installed 2012-12-30 15:30:37 -06:00
Sam Stephenson
eb79a3edaa Merge pull request #292 from sstephenson/help
help system where each command holds its own docs
2012-12-29 20:05:42 -08:00
Sam Stephenson
37eca782cc Documentation tweaks 2012-12-29 22:05:04 -06:00
Sam Stephenson
19666f2598 Wrap documentation comments at 70 columns 2012-12-29 21:50:38 -06:00
Mislav Marohnić
3436bddaea new-style documentation for most commands 2012-12-29 23:34:53 +01:00
Mislav Marohnić
5cc6b0e3d3 allow indented lines in help text
Before, lines of help that were indented were stripped away.
2012-12-29 22:48:28 +01:00
Mislav Marohnić
2b21e22e97 display help for commands that have Summary but not Usage
A command doesn't have to specify Usage docs if it doesn't accept any
arguments. The default usage for a command will be printed as:

    Usage: rbenv ${command}
2012-12-29 22:14:54 +01:00
Sam Stephenson
57df945738 Don't print version before help summary (bare rbenv already does this) 2012-12-29 12:19:06 -06:00
Sam Stephenson
e2e474c59d Add rbenv help --usage 2012-12-29 12:12:47 -06:00
Sam Stephenson
4c19dc22d7 Improve syntax for inline documentation and allow for multi-line usage 2012-12-29 12:06:20 -06:00
Sam Stephenson
ef44b4ccac Merge branch 'master' into help 2012-12-29 11:23:23 -06:00
Mislav Marohnić
8ee2f2657a avoid prepending system ruby to PATH
System ruby is already on PATH (that's the definition of system ruby) and by
duplicating its path by putting it in front, we can break the user's
environment.

Fixes #275
2012-12-29 00:17:16 +01:00
Sam Stephenson
f635c8715c Add zsh support for completion of full command line 2012-12-28 13:25:24 -06:00
Sam Stephenson
3ceeb72ac6 Merge remote-tracking branch 'griff/morecompletion' 2012-12-28 12:43:30 -06:00
Sam Stephenson
e0b8938fef Merge pull request #299 from sstephenson/automatic-local-exec
Automatic local exec
2012-12-28 09:05:24 -08:00
Sam Stephenson
811ca05916 Run hash -r after rbenv rehash when shell integration is enabled
Fixes #119
2012-12-28 10:59:10 -06:00
Sam Stephenson
df9bbd7ab3 Speed up rbenv-rehash with a simpler indexing approach 2012-12-27 17:16:57 -06:00
Sam Stephenson
339e331f1d Ensure outdated shims are removed first when rehashing 2012-12-27 13:42:25 -06:00
Sam Stephenson
283e67b57e When the ruby shim is invoked with a script, set RBENV_DIR to the script's dirname 2012-12-27 13:41:55 -06:00
Sam Stephenson
6c1fb9ffd0 Fall back to $PWD if a local version file can't be found in $RBENV_DIR 2012-12-27 13:39:36 -06:00
Oscar Del Ben
c3fe192243 use ruby-build
Fixes #294
2012-12-20 16:56:56 +01:00
Sam Stephenson
1ebcbd92e2 Tweak rbenv --version output 2012-12-13 11:26:39 -06:00
Mislav Marohnić
3060578e3b use typeset instead of local in rbenv() function
This is to insure portability to ksh.

Fixes #205, references #209
2012-12-13 06:01:26 +01:00
Mislav Marohnić
b8715bfee6 foundation for a help system where each command holds its own docs
Docs are comprised from "Usage", "Summary" and "Help" sections, where
"Help" can span multiple commented lines. If it is missing, "Summary" is
shown in its place.

References #204, references #206
2012-12-13 05:48:28 +01:00
Sam Stephenson
7fe9231e64 Fix rbenv prefix for system version
Should be `/usr` or `/usr/local`, not `/usr/bin` or `/usr/local/bin`
2012-12-12 21:40:57 -06:00
Sam Stephenson
9289af0132 Don't include system in rbenv versions --bare output 2012-12-12 21:40:57 -06:00
Mislav Marohnić
1f7722088d make shell return an error code in case of failure
Fixes #274
2012-12-13 02:58:41 +01:00
Mislav Marohnić
e548877ead have versions also list "system" if it exists
Closes #263
2012-12-13 01:52:52 +01:00
Mislav Marohnić
21391c8d2f put up a note why version-file-read is tricky 2012-12-13 01:45:06 +01:00
Roy Liu
99551dd1ec fix rbenv-which with system ruby
Don't have `command -v` abort the whole script prematurely.
2012-12-13 01:00:24 +01:00
Mislav Marohnić
b5a26936e8 rbenv --version 2012-12-13 00:40:29 +01:00
Ruben Verborgh
cf28136003 speed up rbenv-init
Use `rbenv-commands` instead of `rbenv commands`. The latter
unnecessarily goes through `rbenv` executable.

Fixes #254
2012-12-13 00:18:32 +01:00
Mislav Marohnić
349236c932 tweak docs & add syntax highlighting to instructions 2012-12-12 23:46:10 +01:00
Guillermo Iguaran
0ce6fad14e Merge pull request #287 from mislav/versions-fix
fix `versions` in case current version doesn't exist
2012-12-12 14:12:39 -08:00
Joe Atzberger
0a9e2baef1 fix documentation about manually compiling Ruby
./configure doesn't exist by default in repo: use autoconf to create it.
2012-12-12 23:10:18 +01:00
Mislav Marohnić
da562ad74c replace build system with generated table of contents
Gets rid of `doc/README.mdtoc` and its build script. Since GitHub.com
renders anchors for each heading, all we have to do is put a simple
table of contents into `README.md` itself, and everything will get
linked up nicely.

Pros of this approach:
* We don't have to point out to people not to edit `README.md` anymore
* We don't have to run the build script each time README gets edited

Cons of this change:
* The "chapter" numbers are lost. They were silly anyway.

`doc/mdtoc` renders a Markdown table of contents for a Markdown file.
`doc/filter-toc` filters that down to only headings after ToC.
This script can be used to easily insert ToC into the current document
when editing `README.md` with, e.g., Vim:

    :read !doc/filter-toc %
2012-12-12 23:06:44 +01:00
Guillermo Iguaran
d45dc17f25 Merge pull request #286 from candeira/ubuntu-install-instructions
fix install instructions for ubuntu & other linux
2012-12-12 07:27:21 -08:00
Javier Candeira
7f1aefa09b fix install instructions for ubuntu (using version 12.04, but should work for all versions) 2012-12-12 16:15:28 +11:00
Guillermo Iguaran
2162054659 Merge pull request #288 from mislav/usage-fix
fix obsolete usage instruction
2012-12-11 15:37:57 -08:00
Mislav Marohnić
0ff3ca8a12 fix obsolete usage instruction 2012-12-12 00:32:27 +01:00
Mislav Marohnić
47c8a0e0b8 fix versions in case current version doesn't exist
`rbenv-versions` tries to read the current version to display a marker
next to it, but if that fails the whole script aborts.

This change makes it so that the failures from `rbenv-version-name` are
tolerated. It also makes the `--bare` mode never call it in the first
place, because it doesn't need to display a marker.
2012-12-12 00:25:02 +01:00
Guillermo Iguaran
2a347226df Merge pull request #225 from dentarg/master
Fixed broken link to RVM in documentation
2012-12-11 13:19:53 -08:00
Ryan Bigg
962452d6d1 Merge pull request #188 from tundramonkey/master
Added in short note on Uninstalling Rubies under new 2.4 section in README
2012-12-11 13:13:44 -08:00
Guillermo Iguaran
2df165c49e Sync doc/README.mdtoc with the actual README
All the changes to documentation should be done in doc/README.mdtoc
2012-12-11 16:06:02 -05:00
Guillermo Iguaran
fc3a634e22 Update README: use last version of jruby in examples 2012-12-11 15:56:03 -05:00
Guillermo Iguaran
01a9141780 Merge pull request #278 from mattdbridges/master
Just trying to keep the README.md up to date with Ruby versions
2012-12-11 12:54:11 -08:00
Guillermo Iguaran
f783b9ec0d Merge pull request #258 from baer/patch-1
Installation Step 1 is a one liner
2012-12-11 12:52:36 -08:00
Matt Bridges
b745a51f30 Update README.md
Changing Ruby versions references to latest versions to keep somewhat up-to-date.
2012-11-17 01:57:23 -06:00
Brian Olsen
02332d78f3 Added bash support for completion of full command line 2012-10-05 04:28:25 +02:00
Eric
183c780698 Installation Step 1 is a one liner
Not a big change, just thought it's always good to make it easier for a beginner
2012-08-28 12:37:15 -06:00
Patrik Ragnarsson
406c8e0303 Fixed broken link to RVM in documentation 2012-05-12 22:38:56 +02:00
Sam Stephenson
6778c8e905 Merge pull request #217 from alecchen/master
remove "+=" operator in rbenv-rehash to support bash-3.0
2012-04-23 07:45:44 -07:00
Alec Chen
3a94daeaf8 remove "+=" operator to support bash-3.0 2012-04-23 22:11:19 +08:00
Sam Stephenson
e5c64db280 Merge pull request #203 from cldwalker/options_help
help for versions and commands, including their options
2012-03-23 13:43:25 -07:00
Gabriel Horner
d3700dfd70 help for versions and commands, including their options 2012-03-23 16:21:53 -04:00
Sam Stephenson
975b45dbfe Merge pull request #184 from jvirtanen/fix/typos
Fix typos in documentation
2012-02-18 08:53:30 -08:00
Sam Stephenson
a49b07975c Merge pull request #189 from amarshall/master
Prevent $command from leaking outside of function
2012-02-18 08:52:12 -08:00
Daryl Manning
5e57ab95ce Changed doc/README.mdtoc and built README.md and changed nomenclature to 'ruby versions' as requested. 2012-02-09 16:20:53 +11:00
Andrew Marshall
9c43fa9161 Prevent $command from leaking outside of function 2012-02-04 18:05:43 -05:00
Daryl Manning
9b286ecbfd And better codify the rbenv command just for good measure. 2012-02-03 17:54:07 +11:00
Daryl Manning
b7e9569ccb Embrassing typo in the anchor link neme != name. 2012-02-03 17:52:09 +11:00
Daryl Manning
e922131422 Added in section 2.4 on uninstalling rubies from .rbenv/versions to the README. 2012-02-03 17:48:20 +11:00
Jussi Virtanen
34813ef32c Fix typos in documentation 2012-01-29 11:35:01 +02:00
Sam Stephenson
e899f1d31c Merge pull request #183 from terceiro/new-hooks-dir
Add /usr/lib/rbenv/hooks to hook search path
2012-01-26 16:25:24 -08:00
Antonio Terceiro
d1bfeee334 Add /usr/lib/rbenv/hooks to hook search path
This will help with the packaging of rbenv plugin that contain hooks in
Debian.
2012-01-26 20:23:31 -02:00
Sam Stephenson
9ea1f7d53e Merge pull request #179 from johnwilliams/master
rbenv-init arguments should be allowed in any order
2012-01-17 07:41:55 -08:00
John Williams
f40bc773d2 Allow init arguments to be in any order. 2012-01-17 08:50:40 -06:00
Sam Stephenson
5d0a6630b9 Account for path entries with spaces in remove_from_path 2011-12-30 13:40:22 -06:00
Sam Stephenson
114b81c9a4 Use if instead of inline && so rbenv rehash exits with a zero status 2011-12-26 20:12:16 -06:00
33 changed files with 763 additions and 824 deletions

View File

@@ -1,4 +1,4 @@
Copyright (c) 2011 Sam Stephenson
Copyright (c) 2013 Sam Stephenson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

463
README.md
View File

@@ -1,176 +1,246 @@
# Simple Ruby Version Management: rbenv
# Groom your apps Ruby environment with rbenv.
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.
Use rbenv to pick a Ruby version for your application and guarantee
that your development environment matches production. Put rbenv to work
with [Bundler](http://gembundler.com/) for painless Ruby upgrades and
bulletproof deployments.
<img src="http://i.sstephenson.us/rbenv2.png" width="894" height="464">
**Powerful in development.** Specify your app's Ruby version once,
in a single file. Keep all your teammates on the same page. No
headaches running apps on different versions of Ruby. Just Works™
from the command line and with app servers like [Pow](http://pow.cx).
Override the Ruby version anytime: just set an environment variable.
### rbenv _does…_
**Rock-solid in production.** Your application's executables are its
interface with ops. With rbenv and [Bundler
binstubs](https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs)
you'll never again need to `cd` in a cron job or Chef recipe to
ensure you've selected the right runtime. The Ruby version
dependency lives in one place—your app—so upgrades and rollbacks are
atomic, even when you switch versions.
* Let you **change the global Ruby version** on a per-user basis.
* Provide support for **per-project Ruby versions**.
* Allow you to **override the Ruby version** with an environment
variable.
**One thing well.** rbenv is concerned solely with switching Ruby
versions. It's simple and predictable. A rich plugin ecosystem lets
you tailor it to suit your needs. Compile your own Ruby versions, or
use the [ruby-build](https://github.com/sstephenson/ruby-build)
plugin to automate the process. Specify per-application environment
variables with [rbenv-vars](https://github.com/sstephenson/rbenv-vars).
See more [plugins on the
wiki](https://github.com/sstephenson/rbenv/wiki/Plugins).
### In contrast with rvm, rbenv _does not…_
* **Need to be loaded into your shell.** Instead, rbenv's shim
approach works by adding a directory to your `$PATH`.
* **Override shell commands like `cd`.** That's dangerous and
error-prone.
* **Have a configuration file.** There's nothing to configure except
which version of Ruby you want to use.
* **Install Ruby.** You can build and install Ruby yourself, or use
[ruby-build](https://github.com/sstephenson/ruby-build) to
automate the process.
* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better
way to manage application dependencies. If you have projects that
are not yet using Bundler you can install the
[rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin.
* **Require changes to Ruby libraries for compatibility.** The
simplicity of rbenv means as long as it's in your `$PATH`,
[nothing](https://rvm.beginrescueend.com/integration/bundler/)
[else](https://rvm.beginrescueend.com/integration/capistrano/)
needs to know about it.
* **Prompt you with warnings when you switch to a project.** Instead
of executing arbitrary code, rbenv reads just the version name
from each project. There's nothing to "trust."
[**Why choose rbenv over
RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F)
## Table of Contents
* [1 How It Works](#section_1)
* [2 Installation](#section_2)
* [2.1 Basic GitHub Checkout](#section_2.1)
* [2.1.1 Upgrading](#section_2.1.1)
* [2.2 Homebrew on Mac OS X](#section_2.2)
* [2.3 Neckbeard Configuration](#section_2.3)
* [3 Usage](#section_3)
* [3.1 rbenv global](#section_3.1)
* [3.2 rbenv local](#section_3.2)
* [3.3 rbenv shell](#section_3.3)
* [3.4 rbenv versions](#section_3.4)
* [3.5 rbenv version](#section_3.5)
* [3.6 rbenv rehash](#section_3.6)
* [3.7 rbenv which](#section_3.7)
* [3.8 rbenv whence](#section_3.8)
* [4 Development](#section_4)
* [4.1 Version History](#section_4.1)
* [4.2 License](#section_4.2)
* [How It Works](#how-it-works)
* [Understanding PATH](#understanding-path)
* [Understanding Shims](#understanding-shims)
* [Choosing the Ruby Version](#choosing-the-ruby-version)
* [Locating the Ruby Installation](#locating-the-ruby-installation)
* [Installation](#installation)
* [Basic GitHub Checkout](#basic-github-checkout)
* [Upgrading](#upgrading)
* [Homebrew on Mac OS X](#homebrew-on-mac-os-x)
* [Neckbeard Configuration](#neckbeard-configuration)
* [Uninstalling Ruby Versions](#uninstalling-ruby-versions)
* [Command Reference](#command-reference)
* [rbenv local](#rbenv-local)
* [rbenv global](#rbenv-global)
* [rbenv shell](#rbenv-shell)
* [rbenv versions](#rbenv-versions)
* [rbenv version](#rbenv-version)
* [rbenv rehash](#rbenv-rehash)
* [rbenv which](#rbenv-which)
* [rbenv whence](#rbenv-whence)
* [Development](#development)
* [Version History](#version-history)
* [License](#license)
## <a name="section_1"></a> 1 How It Works
## How It Works
rbenv operates on the per-user directory `~/.rbenv`. Version names in
rbenv correspond to subdirectories of `~/.rbenv/versions`. For
example, you might have `~/.rbenv/versions/1.8.7-p354` and
`~/.rbenv/versions/1.9.3-rc1`.
At at high level, rbenv intercepts Ruby commands using shim
executables injected into your `PATH`, determines which Ruby version
has been specified by your application, and passes your commands along
to the correct Ruby installation.
Each version is a working tree with its own binaries, like
`~/.rbenv/versions/1.8.7-p354/bin/ruby` and
`~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_
for every such binary across all installed versions of Ruby.
### Understanding PATH
These shims are simple wrapper scripts that live in `~/.rbenv/shims`
and detect which Ruby version you want to use. They insert the
directory for the selected version at the beginning of your `$PATH`
and then execute the corresponding binary.
When you run a command like `ruby` or `rake`, your operating system
searches through a list of directories to find an executable file with
that name. This list of directories lives in an environment variable
called `PATH`, with each directory in the list separated by a colon:
Because of the simplicity of the shim approach, all you need to use
rbenv is `~/.rbenv/shims` in your `$PATH`.
/usr/local/bin:/usr/bin:/bin
## <a name="section_2"></a> 2 Installation
Directories in `PATH` are searched from left to right, so a matching
executable in a directory at the beginning of the list takes
precedence over another one at the end. In this example, the
`/usr/local/bin` directory will be searched first, then `/usr/bin`,
then `/bin`.
**Compatibility note**: rbenv is _incompatible_ with rvm. Things will
appear to work until you try to install a gem. The problem is that
rvm actually overrides the `gem` command with a shell function!
Please remove any references to rvm before using rbenv.
### Understanding Shims
### <a name="section_2.1"></a> 2.1 Basic GitHub Checkout
rbenv works by inserting a directory of _shims_ at the front of your
`PATH`:
~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin
Through a process called _rehashing_, rbenv maintains shims in that
directory to match every Ruby command across every installed version
of Ruby—`irb`, `gem`, `rake`, `rails`, `ruby`, and so on.
Shims are lightweight executables that simply pass your command along
to rbenv. So with rbenv installed, when you run, say, `rake`, your
operating system will do the following:
* Search your `PATH` for an executable file named `rake`
* Find the rbenv shim named `rake` at the beginning of your `PATH`
* Run the shim named `rake`, which in turn passes the command along to
rbenv
### Choosing the Ruby Version
When you execute a shim, rbenv determines which Ruby version to use by
reading it from the following sources, in this order:
1. The `RBENV_VERSION` environment variable, if specified. You can use
the [`rbenv shell`](#rbenv-shell) command to set this environment
variable in your current shell session.
2. The application-specific `.ruby-version` file in the current
directory, if present. You can modify the current directory's
`.ruby-version` file with the [`rbenv local`](#rbenv-local)
command.
3. The first `.ruby-version` file found by searching each parent
directory until reaching the root of your filesystem, if any.
4. The global `~/.rbenv/version` file. You can modify this file using
the [`rbenv global`](#rbenv-global) command. If the global version
file is not present, rbenv assumes you want to use the "system"
Ruby—i.e. whatever version would be run if rbenv weren't in your
path.
### Locating the Ruby Installation
Once rbenv has determined which version of Ruby your application has
specified, it passes the command along to the corresponding Ruby
installation.
Each Ruby version is installed into its own directory under
`~/.rbenv/versions`. For example, you might have these versions
installed:
* `~/.rbenv/versions/1.8.7-p371/`
* `~/.rbenv/versions/1.9.3-p327/`
* `~/.rbenv/versions/jruby-1.7.1/`
Version names to rbenv are simply the names of the directories in
`~/.rbenv/versions`.
## Installation
**Compatibility note**: rbenv is _incompatible_ with RVM. Please make
sure to fully uninstall RVM and remove any references to it from
your shell initialization files before installing rbenv.
If you're on Mac OS X, consider
[installing with Homebrew](#homebrew-on-mac-os-x).
### Basic GitHub Checkout
This will get you going with the latest version of rbenv and make it
easy to fork and contribute any changes back upstream.
1. Check out rbenv into `~/.rbenv`.
$ cd
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
~~~ sh
$ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
~~~
2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
command-line utility.
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
~~~ sh
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
~~~
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
**Ubuntu note**: Modify your `~/.profile` instead of `~/.bash_profile`.
3. Add rbenv init to your shell to enable shims and autocompletion.
**Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`.
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
3. Add `rbenv init` to your shell to enable shims and autocompletion.
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
~~~ sh
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
~~~
4. Restart your shell so the path changes take effect. You can now
begin using rbenv.
_Same as in previous step, use `~/.profile` on Ubuntu, `~/.zshrc` for zsh._
$ exec $SHELL
4. Restart your shell as a login shell so the path changes take effect.
You can now begin using rbenv.
5. Install Ruby versions into `~/.rbenv/versions`. For example, to
install Ruby 1.9.2-p290, download and unpack the source, then run:
~~~ sh
$ exec $SHELL -l
~~~
$ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290
$ make
$ make install
5. Install [ruby-build](https://github.com/sstephenson/ruby-build),
which provides an `rbenv install` command that simplifies the
process of installing new Ruby versions.
The [ruby-build](https://github.com/sstephenson/ruby-build) project
provides an `rbenv install` command that simplifies the process of
installing new Ruby versions to:
~~~
$ rbenv install 1.9.3-p327
~~~
$ rbenv install 1.9.2-p290
As an alternative, you can download and compile Ruby yourself into
`~/.rbenv/versions/`.
6. Rebuild the shim binaries. You should do this any time you install
a new Ruby binary (for example, when installing a new Ruby version,
or when installing a gem that provides a binary).
6. Rebuild the shim executables. You should do this any time you
install a new Ruby executable (for example, when installing a new
Ruby version, or when installing a gem that provides a command).
$ rbenv rehash
~~~
$ rbenv rehash
~~~
#### <a name="section_2.1.1"></a> 2.1.1 Upgrading
#### Upgrading
If you've installed rbenv using the instructions above, you can
upgrade your installation at any time using git.
If you've installed rbenv manually using git, you can upgrade your
installation to the cutting-edge version at any time.
To upgrade to the latest development version of rbenv, use `git pull`:
~~~ sh
$ cd ~/.rbenv
$ git pull
~~~
$ cd ~/.rbenv
$ git pull
To use a specific release of rbenv, check out the corresponding tag:
To upgrade to a specific release of rbenv, check out the corresponding
tag:
~~~ sh
$ cd ~/.rbenv
$ git fetch
$ git checkout v0.3.0
~~~
$ cd ~/.rbenv
$ git fetch
$ git tag
v0.1.0
v0.1.1
v0.1.2
v0.2.0
$ git checkout v0.2.0
### <a name="section_2.2"></a> 2.2 Homebrew on Mac OS X
### Homebrew on Mac OS X
You can also install rbenv using the
[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS
X.
$ brew update
$ brew install rbenv
$ brew install ruby-build
~~~
$ brew update
$ brew install rbenv
$ brew install ruby-build
~~~
The same commands can be used for upgrading.
To later update these installs, use `upgrade` instead of `install`.
Afterwards you'll still need to add `eval "$(rbenv init -)"` to your
profile as stated in the caveats. You'll only ever have to do this
once.
### <a name="section_2.3"></a> 2.3 Neckbeard Configuration
### Neckbeard Configuration
Skip this section unless you must know what every line in your shell
profile is doing.
@@ -202,19 +272,53 @@ opposed to this idea. Here's what `rbenv init` actually does:
Run `rbenv init -` for yourself to see exactly what happens under the
hood.
## <a name="section_3"></a> 3 Usage
### Uninstalling Ruby Versions
As time goes on, Ruby versions you install will accumulate in your
`~/.rbenv/versions` directory.
To remove old Ruby versions, simply `rm -rf` the directory of the
version you want to remove. You can find the directory of a particular
Ruby verison with the `rbenv prefix` command, e.g. `rbenv prefix
1.8.7-p357`.
The [ruby-build](https://github.com/sstephenson/ruby-build) plugin
provides an `rbenv uninstall` command to automate the removal
process.
## Command Reference
Like `git`, the `rbenv` command delegates to subcommands based on its
first argument. The most common subcommands are:
### <a name="section_3.1"></a> 3.1 rbenv global
### rbenv local
Sets a local application-specific Ruby version by writing the version
name to a `.ruby-version` file in the current directory. This version
overrides the global version, and can be overridden itself by setting
the `RBENV_VERSION` environment variable or with the `rbenv shell`
command.
$ rbenv local 1.9.3-p327
When run without a version number, `rbenv local` reports the currently
configured local version. You can also unset the local version:
$ rbenv local --unset
Previous versions of rbenv stored local version specifications in a
file named `.rbenv-version`. For backwards compatibility, rbenv will
read a local version specified in an `.rbenv-version` file, but a
`.ruby-version` file in the same directory will take precedence.
### rbenv global
Sets the global version of Ruby to be used in all shells by writing
the version name to the `~/.rbenv/version` file. This version can be
overridden by a per-project `.rbenv-version` file, or by setting the
`RBENV_VERSION` environment variable.
overridden by an application-specific `.ruby-version` file, or by
setting the `RBENV_VERSION` environment variable.
$ rbenv global 1.9.2-p290
$ rbenv global 1.8.7-p352
The special version name `system` tells rbenv to use the system Ruby
(detected by searching your `$PATH`).
@@ -222,28 +326,13 @@ The special version name `system` tells rbenv to use the system Ruby
When run without a version number, `rbenv global` reports the
currently configured global version.
### <a name="section_3.2"></a> 3.2 rbenv local
Sets a local per-project Ruby version by writing the version name to
an `.rbenv-version` file in the current directory. This version
overrides the global, and can be overridden itself by setting the
`RBENV_VERSION` environment variable or with the `rbenv shell`
command.
$ rbenv local rbx-1.2.4
When run without a version number, `rbenv local` reports the currently
configured local version. You can also unset the local version:
$ rbenv local --unset
### <a name="section_3.3"></a> 3.3 rbenv shell
### rbenv shell
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
environment variable in your shell. This version overrides both
project-specific versions and the global version.
environment variable in your shell. This version overrides
application-specific versions and the global version.
$ rbenv shell jruby-1.6.4
$ rbenv shell jruby-1.7.1
When run without a version number, `rbenv shell` reports the current
value of `RBENV_VERSION`. You can also unset the shell version:
@@ -255,9 +344,9 @@ the installation instructions) in order to use this command. If you
prefer not to use shell integration, you may simply set the
`RBENV_VERSION` variable yourself:
$ export RBENV_VERSION=jruby-1.6.4
$ export RBENV_VERSION=jruby-1.7.1
### <a name="section_3.4"></a> 3.4 rbenv versions
### rbenv versions
Lists all Ruby versions known to rbenv, and shows an asterisk next to
the currently active version.
@@ -265,45 +354,45 @@ the currently active version.
$ rbenv versions
1.8.7-p352
1.9.2-p290
* 1.9.3-rc1 (set by /Users/sam/.rbenv/global)
jruby-1.6.4
* 1.9.3-p327 (set by /Users/sam/.rbenv/version)
jruby-1.7.1
rbx-1.2.4
ree-1.8.7-2011.03
### <a name="section_3.5"></a> 3.5 rbenv version
### rbenv version
Displays the currently active Ruby version, along with information on
how it was set.
$ rbenv version
1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version)
1.8.7-p352 (set by /Volumes/37signals/basecamp/.ruby-version)
### <a name="section_3.6"></a> 3.6 rbenv rehash
### rbenv rehash
Installs shims for all Ruby binaries known to rbenv (i.e.,
Installs shims for all Ruby executables known to rbenv (i.e.,
`~/.rbenv/versions/*/bin/*`). Run this command after you install a new
version of Ruby, or install a gem that provides binaries.
version of Ruby, or install a gem that provides commands.
$ rbenv rehash
### <a name="section_3.7"></a> 3.7 rbenv which
### rbenv which
Displays the full path to the binary that rbenv will execute when you
run the given command.
Displays the full path to the executable that rbenv will invoke when
you run the given command.
$ rbenv which irb
/Users/sam/.rbenv/versions/1.9.2-p290/bin/irb
/Users/sam/.rbenv/versions/1.9.3-p327/bin/irb
### <a name="section_3.8"></a> 3.8 rbenv whence
### rbenv whence
Lists all Ruby versions with the given command installed.
$ rbenv whence rackup
1.9.3-rc1
jruby-1.6.4
1.9.3-p327
jruby-1.7.1
ree-1.8.7-2011.03
## <a name="section_4"></a> 4 Development
## Development
The rbenv source code is [hosted on
GitHub](https://github.com/sstephenson/rbenv). It's clean, modular,
@@ -312,7 +401,57 @@ and easy to understand, even if you're not a shell hacker.
Please feel free to submit pull requests and file bugs on the [issue
tracker](https://github.com/sstephenson/rbenv/issues).
### <a name="section_4.1"></a> 4.1 Version History
### Version History
**0.4.0** (January 4, 2013)
* rbenv now prefers `.ruby-version` files to `.rbenv-version` files
for specifying local application-specific versions. The
`.ruby-version` file has the same format as `.rbenv-version` but is
[compatible with other Ruby version
managers](https://gist.github.com/1912050).
* Deprecated `ruby-local-exec` and moved its functionality into the
standard `ruby` shim. See the [ruby-local-exec wiki
page](https://github.com/sstephenson/wiki/ruby-local-exec) for
upgrade instructions.
* Modified shims to include the full path to rbenv so that they can be
invoked without having rbenv's bin directory in the `$PATH`.
* Sped up `rbenv init` by avoiding rbenv reinintialization and by
using a simpler indexing approach. (Users of
[chef-rbenv](https://github.com/fnichol/chef-rbenv) should upgrade
to the latest version to fix a [compatibility
issue](https://github.com/fnichol/chef-rbenv/pull/26).)
* Reworked `rbenv help` so that usage and documentation is stored as a
comment in each subcommand, enabling plugin commands to hook into
the help system.
* Added support for full completion of the command line, not just the
first argument.
* Updated installation instructions for Zsh and Ubuntu users.
* Fixed `rbenv which` and `rbenv prefix` with system Ruby versions.
* Changed `rbenv exec` to avoid prepending the system Ruby location to
`$PATH` to fix issues running system Ruby commands that invoke other
commands.
* Changed `rbenv rehash` to ensure it exits with a 0 status code under
normal operation, and to ensure outdated shims are removed first
when rehashing.
* Modified `rbenv rehash` to run `hash -r` afterwards, when shell
integration is enabled, to ensure the shell's command cache is
cleared.
* Removed use of the `+=` operator to support older versions of Bash.
* Adjusted non-bare `rbenv versions` output to include `system`, if
present.
* Improved documentation for installing and uninstalling Ruby
versions.
* Fixed `rbenv versions` not to display a warning if the currently
specified version doesn't exist.
* Fixed an instance of local variable leakage in the `rbenv` shell
function wrapper.
* Changed `rbenv shell` to ensure it exits with a non-zero status on
failure.
* Added `rbenv --version` for printing the current version of rbenv.
* Added `/usr/lib/rbenv/hooks` to the plugin hook search path.
* Fixed `rbenv which` to account for path entries with spaces.
* Changed `rbenv init` to accept option arguments in any order.
**0.3.0** (December 25, 2011)
@@ -388,11 +527,11 @@ tracker](https://github.com/sstephenson/rbenv/issues).
* Initial public release.
### <a name="section_4.2"></a> 4.2 License
### License
(The MIT license)
Copyright (c) 2011 Sam Stephenson
Copyright (c) 2013 Sam Stephenson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -13,4 +13,11 @@
set -e
export RBENV_DIR="${1%/*}"
[ -n "$RBENV_SILENCE_WARNINGS" ] || {
echo "rbenv: \`ruby-local-exec' is deprecated and will be removed in the next release."
echo " To upgrade: https://github.com/sstephenson/rbenv/wiki/ruby-local-exec"
echo
} >&2
exec ruby "$@"

View File

@@ -5,8 +5,10 @@ _rbenv() {
if [ "$COMP_CWORD" -eq 1 ]; then
COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") )
else
local command="${COMP_WORDS[1]}"
local completions="$(rbenv completions "$command")"
local words=("${COMP_WORDS[@]}")
unset words[0]
unset words[$COMP_CWORD]
local completions=$(rbenv completions "${words[@]}")
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
fi
}

View File

@@ -5,14 +5,13 @@ fi
compctl -K _rbenv rbenv
_rbenv() {
local word words completions
local words completions
read -cA words
word="${words[2]}"
if [ "${#words}" -eq 2 ]; then
completions="$(rbenv commands)"
else
completions="$(rbenv completions "${word}")"
completions="$(rbenv completions ${words[2,-1]})"
fi
reply=("${(ps:\n:)completions}")

View File

@@ -1,395 +0,0 @@
# Simple Ruby Version Management: rbenv
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/rbenv2.png" width="894" height="464">
### rbenv _does…_
* Let you **change the global Ruby version** on a per-user basis.
* Provide support for **per-project Ruby versions**.
* Allow you to **override the Ruby version** with an environment
variable.
### In contrast with rvm, rbenv _does not…_
* **Need to be loaded into your shell.** Instead, rbenv's shim
approach works by adding a directory to your `$PATH`.
* **Override shell commands like `cd`.** That's dangerous and
error-prone.
* **Have a configuration file.** There's nothing to configure except
which version of Ruby you want to use.
* **Install Ruby.** You can build and install Ruby yourself, or use
[ruby-build](https://github.com/sstephenson/ruby-build) to
automate the process.
* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better
way to manage application dependencies. If you have projects that
are not yet using Bundler you can install the
[rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin.
* **Require changes to Ruby libraries for compatibility.** The
simplicity of rbenv means as long as it's in your `$PATH`,
[nothing](https://rvm.beginrescueend.com/integration/bundler/)
[else](https://rvm.beginrescueend.com/integration/capistrano/)
needs to know about it.
* **Prompt you with warnings when you switch to a project.** Instead
of executing arbitrary code, rbenv reads just the version name
from each project. There's nothing to "trust."
## Table of Contents
## How It Works ##
rbenv operates on the per-user directory `~/.rbenv`. Version names in
rbenv correspond to subdirectories of `~/.rbenv/versions`. For
example, you might have `~/.rbenv/versions/1.8.7-p354` and
`~/.rbenv/versions/1.9.3-rc1`.
Each version is a working tree with its own binaries, like
`~/.rbenv/versions/1.8.7-p354/bin/ruby` and
`~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_
for every such binary across all installed versions of Ruby.
These shims are simple wrapper scripts that live in `~/.rbenv/shims`
and detect which Ruby version you want to use. They insert the
directory for the selected version at the beginning of your `$PATH`
and then execute the corresponding binary.
Because of the simplicity of the shim approach, all you need to use
rbenv is `~/.rbenv/shims` in your `$PATH`.
## Installation ##
**Compatibility note**: rbenv is _incompatible_ with rvm. Things will
appear to work until you try to install a gem. The problem is that
rvm actually overrides the `gem` command with a shell function!
Please remove any references to rvm before using rbenv.
### Basic GitHub Checkout ###
This will get you going with the latest version of rbenv and make it
easy to fork and contribute any changes back upstream.
1. Check out rbenv into `~/.rbenv`.
$ cd
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
command-line utility.
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.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 `~/.zshenv` file instead of `~/.bash_profile`.
4. Restart your shell so the path changes take effect. You can now
begin using rbenv.
$ exec $SHELL
5. Install Ruby versions into `~/.rbenv/versions`. For example, to
install Ruby 1.9.2-p290, download and unpack the source, then run:
$ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290
$ make
$ make install
The [ruby-build](https://github.com/sstephenson/ruby-build) project
provides an `rbenv install` command that simplifies the process of
installing new Ruby versions to:
$ rbenv install 1.9.2-p290
6. Rebuild the shim binaries. You should do this any time you install
a new Ruby binary (for example, when installing a new Ruby version,
or when installing a gem that provides a binary).
$ rbenv rehash
#### Upgrading ####
If you've installed rbenv using the instructions above, you can
upgrade your installation at any time using git.
To upgrade to the latest development version of rbenv, use `git pull`:
$ cd ~/.rbenv
$ git pull
To upgrade to a specific release of rbenv, check out the corresponding
tag:
$ cd ~/.rbenv
$ git fetch
$ git tag
v0.1.0
v0.1.1
v0.1.2
v0.2.0
$ git checkout v0.2.0
### Homebrew on Mac OS X ###
You can also install rbenv using the
[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS
X.
$ brew update
$ brew install rbenv
$ brew install ruby-build
The same commands can be used for upgrading.
Afterwards you'll still need to add `eval "$(rbenv init -)"` to your
profile as stated in the caveats. You'll only ever have to do this
once.
### Neckbeard Configuration ###
Skip this section unless you must know what every line in your shell
profile is doing.
`rbenv init` is the only command that crosses the line of loading
extra commands into your shell. Coming from rvm, some of you might be
opposed to this idea. Here's what `rbenv init` actually does:
1. Sets up your shims path. This is the only requirement for rbenv to
function properly. You can do this by hand by prepending
`~/.rbenv/shims` to your `$PATH`.
2. Installs autocompletion. This is entirely optional but pretty
useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that
up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh
users.
3. Rehashes shims. From time to time you'll need to rebuild your
shim files. Doing this on init makes sure everything is up to
date. You can always run `rbenv rehash` manually.
4. Installs the sh dispatcher. This bit is also optional, but allows
rbenv and plugins to change variables in your current shell, making
commands like `rbenv shell` possible. The sh dispatcher doesn't do
anything crazy like override `cd` or hack your shell prompt, but if
for some reason you need `rbenv` to be a real script rather than a
shell function, you can safely skip it.
Run `rbenv init -` for yourself to see exactly what happens under the
hood.
## Usage ##
Like `git`, the `rbenv` command delegates to subcommands based on its
first argument. The most common subcommands are:
### rbenv global ###
Sets the global version of Ruby to be used in all shells by writing
the version name to the `~/.rbenv/version` file. This version can be
overridden by a per-project `.rbenv-version` file, or by setting the
`RBENV_VERSION` environment variable.
$ rbenv global 1.9.2-p290
The special version name `system` tells rbenv to use the system Ruby
(detected by searching your `$PATH`).
When run without a version number, `rbenv global` reports the
currently configured global version.
### rbenv local ###
Sets a local per-project Ruby version by writing the version name to
an `.rbenv-version` file in the current directory. This version
overrides the global, and can be overridden itself by setting the
`RBENV_VERSION` environment variable or with the `rbenv shell`
command.
$ rbenv local rbx-1.2.4
When run without a version number, `rbenv local` reports the currently
configured local version. You can also unset the local version:
$ rbenv local --unset
### rbenv shell ###
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
environment variable in your shell. This version overrides both
project-specific versions and the global version.
$ rbenv shell jruby-1.6.4
When run without a version number, `rbenv shell` reports the current
value of `RBENV_VERSION`. You can also unset the shell version:
$ rbenv shell --unset
Note that you'll need rbenv's shell integration enabled (step 3 of
the installation instructions) in order to use this command. If you
prefer not to use shell integration, you may simply set the
`RBENV_VERSION` variable yourself:
$ export RBENV_VERSION=jruby-1.6.4
### rbenv versions ###
Lists all Ruby versions known to rbenv, and shows an asterisk next to
the currently active version.
$ rbenv versions
1.8.7-p352
1.9.2-p290
* 1.9.3-rc1 (set by /Users/sam/.rbenv/global)
jruby-1.6.4
rbx-1.2.4
ree-1.8.7-2011.03
### rbenv version ###
Displays the currently active Ruby version, along with information on
how it was set.
$ rbenv version
1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version)
### rbenv rehash ###
Installs shims for all Ruby binaries known to rbenv (i.e.,
`~/.rbenv/versions/*/bin/*`). Run this command after you install a new
version of Ruby, or install a gem that provides binaries.
$ rbenv rehash
### rbenv which ###
Displays the full path to the binary that rbenv will execute when you
run the given command.
$ rbenv which irb
/Users/sam/.rbenv/versions/1.9.2-p290/bin/irb
### rbenv whence ###
Lists all Ruby versions with the given command installed.
$ rbenv whence rackup
1.9.3-rc1
jruby-1.6.4
ree-1.8.7-2011.03
## Development ##
The rbenv source code is [hosted on
GitHub](https://github.com/sstephenson/rbenv). It's clean, modular,
and easy to understand, even if you're not a shell hacker.
Please feel free to submit pull requests and file bugs on the [issue
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
absolute path. This fixes an issue where Ruby scripts using the
`ruby-local-exec` wrapper would go into an infinite loop when
invoked with a relative path from the command line.
**0.2.0** (September 28, 2011)
* Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local`
to `rbenv local`. The `set-` commands are deprecated and will be
removed in the next major release.
* rbenv now uses `greadlink` on Solaris.
* Added a `ruby-local-exec` command which can be used in shebangs in
place of `#!/usr/bin/env ruby` to properly set the project-specific
Ruby version regardless of current working directory.
* Fixed an issue with `rbenv rehash` when no binaries are present.
* Added support for `rbenv-sh-*` commands, which run inside the
current shell instead of in a child process.
* Added an `rbenv shell` command for conveniently setting the
`$RBENV_VERSION` environment variable.
* Added support for storing rbenv versions and shims in directories
other than `~/.rbenv` with the `$RBENV_ROOT` environment variable.
* Added support for debugging rbenv via `set -x` when the
`$RBENV_DEBUG` environment variable is set.
* Refactored the autocompletion system so that completions are now
built-in to each command and shared between bash and Zsh.
* Added support for plugin bundles in `~/.rbenv/plugins` as documented
in [issue #102](https://github.com/sstephenson/rbenv/pull/102).
* Added `/usr/local/etc/rbenv.d` to the list of directories searched
for rbenv hooks.
* Added support for an `$RBENV_DIR` environment variable which
defaults to the current working directory for specifying where rbenv
searches for local version files.
**0.1.2** (August 16, 2011)
* Fixed rbenv to be more resilient against nonexistent entries in
`$PATH`.
* Made the `rbenv rehash` command operate atomically.
* Modified the `rbenv init` script to automatically run `rbenv
rehash` so that shims are recreated whenever a new shell is opened.
* Added initial support for Zsh autocompletion.
* Removed the dependency on egrep for reading version files.
**0.1.1** (August 14, 2011)
* Fixed a syntax error in the `rbenv help` command.
* Removed `-e` from the shebang in favor of `set -e` at the top of
each file for compatibility with operating systems that do not
support more than one argument in the shebang.
**0.1.0** (August 11, 2011)
* Initial public release.
### License ###
(The MIT license)
Copyright (c) 2011 Sam Stephenson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,4 +0,0 @@
#!/bin/sh -e
ruby mdtoc.rb README.mdtoc > ../README.md

View File

@@ -1,82 +0,0 @@
#!/usr/bin/env ruby
# A little Markdown filter that scans your document for headings,
# numbers them, adds anchors, and inserts a table of contents.
#
# To use it, make sure the headings you want numbered and linked are
# in this format:
#
# ### Title ###
#
# I.e. they must have an equal number of octothorpes around the title
# text. (In Markdown, `#` means `h1`, `##` means `h2`, and so on.)
# The table of contents will be inserted before the first such
# heading.
#
# Released into the public domain.
# Sam Stephenson <sstephenson@gmail.com>
# 2011-04-30
def mdtoc(markdown)
titles = []
lines = markdown.split($/)
start = nil
# First pass: Scan the Markdown source looking for titles of the
# format: `### Title ###`. Record the line number, header level
# (number of octothorpes), and text of each matching title.
lines.each_with_index do |line, line_no|
if line.match(/^(\#{1,6})\s+(.+?)\s+\1$/)
titles << [line_no, $1.length, $2]
start ||= line_no
end
end
last_section = nil
last_level = nil
# Second pass: Iterate over all matched titles and compute their
# corresponding section numbers. Then replace the titles with
# annotated anchors.
titles.each do |title_info|
line_no, level, text = title_info
if last_section
section = last_section.dup
if last_level < level
section << 1
else
(last_level - level).times { section.pop }
section[-1] += 1
end
else
section = [1]
end
name = section.join(".")
lines[line_no] = %(#{"#" * level} <a name="section_#{name}"></a> #{name} #{text})
title_info << section
last_section = section
last_level = level
end
# Third pass: Iterate over matched titles once more to produce the
# table of contents. Then insert it immediately above the first
# matched title.
if start
toc = titles.map do |(line_no, level, text, section)|
name = section.join(".")
%(#{" " * (section.length * 3)}* [#{name} #{text}](#section_#{name}))
end + [""]
lines.insert(start, *toc)
end
lines.join("\n")
end
if __FILE__ == $0
puts mdtoc($<.read)
end

View File

@@ -48,7 +48,7 @@ for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do
done
export PATH="${bin_path}:${PATH}"
hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d"
hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do
hook_path="${hook_path}:${plugin_hook}"
done
@@ -60,7 +60,10 @@ shopt -u nullglob
command="$1"
case "$command" in
"" | "-h" | "--help" )
echo -e "rbenv 0.3.0\n$(rbenv-help)" >&2
echo -e "$(rbenv---version)\n$(rbenv-help)" >&2
;;
"-v" )
exec rbenv---version
;;
* )
command_path="$(command -v "rbenv-$command" || true)"

21
libexec/rbenv---version Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Summary: Display the version of rbenv
#
# Displays the version number of this rbenv release, including the
# current revision from git, if available.
#
# The format of the git revision is:
# <version>-<num_commits>-<git_sha>
# where `num_commits` is the number of commits since `version` was
# tagged.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
version="0.4.0"
cd "$RBENV_ROOT"
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}"
echo "rbenv ${git_revision:-$version}"

View File

@@ -1,4 +1,7 @@
#!/usr/bin/env bash
# Summary: List all available rbenv commands
# Usage: rbenv commands [--sh|--no-sh]
set -e
[ -n "$RBENV_DEBUG" ] && set -x

View File

@@ -1,10 +1,12 @@
#!/usr/bin/env bash
# Usage: rbenv completions <command> [arg1 arg2...]
set -e
[ -n "$RBENV_DEBUG" ] && set -x
COMMAND="$1"
if [ -z "$COMMAND" ]; then
echo "usage: rbenv completions COMMAND [arg1 arg2...]" >&2
rbenv-help --usage completions >&2
exit 1
fi

View File

@@ -1,4 +1,18 @@
#!/usr/bin/env bash
#
# Summary: Run an executable with the selected Ruby version
#
# Usage: rbenv exec <command> [arg1 arg2...]
#
# Runs an executable by first preparing PATH so that the selected Ruby
# version's `bin' directory is at the front.
#
# For example, if the currently selected Ruby version is 1.9.3-p327:
# rbenv exec bundle install
#
# is equivalent to:
# PATH="$RBENV_ROOT/versions/1.9.3-p327/bin:$PATH" bundle install
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -7,9 +21,11 @@ if [ "$1" = "--complete" ]; then
exec rbenv shims --short
fi
export RBENV_VERSION="$(rbenv-version-name)"
RBENV_COMMAND="$1"
if [ -z "$RBENV_COMMAND" ]; then
echo "usage: rbenv exec COMMAND [arg1 arg2...]" >&2
rbenv-help --usage exec >&2
exit 1
fi
@@ -21,5 +37,7 @@ for script in $(rbenv-hooks exec); do
done
shift 1
export PATH="${RBENV_BIN_PATH}:${PATH}"
if [ "$RBENV_VERSION" != "system" ]; then
export PATH="${RBENV_BIN_PATH}:${PATH}"
fi
exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@"

View File

@@ -1,4 +1,17 @@
#!/usr/bin/env bash
#
# Summary: Set or show the global Ruby version
#
# Usage: rbenv global <version>
#
# Sets the global Ruby version. You can override the global version at
# any time by setting a directory-specific version with `rbenv local'
# or by setting the `RBENV_VERSION' environment variable.
#
# <version> should be a string matching a Ruby version known to rbenv.
# The special version string `system' will use your default system Ruby.
# Run `rbenv versions' for a list of available Ruby versions.
set -e
[ -n "$RBENV_DEBUG" ] && set -x

View File

@@ -1,88 +1,162 @@
#!/usr/bin/env bash
#
# Summary: Display help for a command
#
# Usage: rbenv help [--usage] COMMAND
#
# Parses and displays help contents from a command's source file.
#
# A command is considered documented if it starts with a comment block
# that has a `Summary:' or `Usage:' section. Usage instructions can
# span multiple lines as long as subsequent lines are indented.
# The remainder of the comment block is displayed as extended
# documentation.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
print_set_version() {
echo "<version> should be a string matching a Ruby version known by rbenv."
local versions="$(rbenv-versions --bare)"
if [ -z "$versions" ]; then
echo "There are currently no Ruby versions installed for rbenv."
else
echo "The currently installed Ruby versions are:"
echo "$versions" | sed 's/^/ /'
fi
echo
echo "The special version string 'system' will use your default system Ruby."
command_path() {
local command="$1"
command -v rbenv-"$command" || command -v rbenv-sh-"$command" || true
}
case "$1" in
"") echo "usage: rbenv <command> [<args>]
extract_initial_comment_block() {
sed -ne "
/^#/ !{
q
}
Some useful rbenv commands are:
commands List all rbenv commands
rehash Rehash rbenv shims (run this after installing binaries)
global Set or show the global Ruby version
local Set or show the local directory-specific Ruby version
shell Set or show the shell-specific Ruby version
version Show the current Ruby version
versions List all Ruby versions known by rbenv
which Show the full path for the given Ruby command
whence List all Ruby versions with the given command
s/^#$/# /
See 'rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme"
;;
global) echo "usage: rbenv global <version>
/^# / {
s/^# //
p
}
"
}
Sets the global Ruby version. You can override the global version at
any time by setting a directory-specific version with \`rbenv local'
or by setting the RBENV_VERSION environment variable.
collect_documentation() {
awk '
/^Summary:/ {
summary = substr($0, 10)
next
}
$(print_set_version)"
;;
local) echo "usage: rbenv local <version>
rbenv local --unset
/^Usage:/ {
reading_usage = 1
usage = usage "\n" $0
next
}
Sets the local directory-specific Ruby version by writing the version
name to a file named '.rbenv-version'.
/^( *$| )/ && reading_usage {
usage = usage "\n" $0
next
}
When you run a Ruby command, rbenv will look for an '.rbenv-version'
file in the current directory and each parent directory. If no such
file is found in the tree, rbenv will use the global Ruby version
specified with \`rbenv global', or the version specified in the
RBENV_VERSION environment variable.
{
reading_usage = 0
help = help "\n" $0
}
$(print_set_version)"
;;
shell) echo "usage: rbenv shell <version>
rbenv shell --unset
function escape(str) {
gsub(/[`\\$"]/, "\\\\&", str)
return str
}
Sets a shell-specific Ruby version by setting the 'RBENV_VERSION'
environment variable in your shell. This version overrides both
project-specific versions and the global version.
function trim(str) {
gsub(/^\n*/, "", str)
gsub(/\n*$/, "", str)
return str
}
$(print_set_version)"
;;
which) echo "usage: rbenv which <command>
END {
if (usage || summary) {
print "summary=\"" escape(summary) "\""
print "usage=\"" escape(trim(usage)) "\""
print "help=\"" escape(trim(help)) "\""
}
}
'
}
Displays the full path to the binary that rbenv will execute when you
run the given command."
;;
whence) echo "usage: rbenv whence <command>
Lists all Ruby versions with the given command installed."
;;
*)
command_path="$(command -v "rbenv-$1" || true)"
if [ -n "$command_path" ]; then
echo "Sorry, the \`$1' command isn't documented yet."
echo
echo "You can view the command's source here:"
echo "$command_path"
echo
else
echo "rbenv: no such command \`$1'"
documentation_for() {
local filename="$(command_path "$1")"
if [ -n "$filename" ]; then
extract_initial_comment_block < "$filename" | collect_documentation
fi
esac
}
print_summary() {
local command="$1"
local summary usage help
eval "$(documentation_for "$command")"
if [ -n "$summary" ]; then
printf " %-9s %s\n" "$command" "$summary"
fi
}
print_summaries() {
for command; do
print_summary "$command"
done
}
print_help() {
local command="$1"
local summary usage help
eval "$(documentation_for "$command")"
[ -n "$help" ] || help="$summary"
if [ -n "$usage" -o -n "$summary" ]; then
if [ -n "$usage" ]; then
echo "$usage"
else
echo "Usage: rbenv ${command}"
fi
if [ -n "$help" ]; then
echo
echo "$help"
echo
fi
else
echo "Sorry, this command isn't documented yet." >&2
return 1
fi
}
print_usage() {
local command="$1"
local summary usage help
eval "$(documentation_for "$command")"
[ -z "$usage" ] || echo "$usage"
}
unset usage
if [ "$1" = "--usage" ]; then
usage="1"
shift
fi
if [ -z "$1" ] || [ "$1" == "rbenv" ]; then
echo "Usage: rbenv <command> [<args>]"
[ -z "$usage" ] || exit
echo
echo "Some useful rbenv commands are:"
print_summaries commands local global shell install uninstall rehash version versions which whence
echo
echo "See \`rbenv help <command>' for information on a specific command."
echo "For full documentation, see: https://github.com/sstephenson/rbenv#readme"
else
command="$1"
if [ -n "$(command_path "$command")" ]; then
if [ -n "$usage" ]; then
print_usage "$command"
else
print_help "$command"
fi
else
echo "rbenv: no such command \`$command'" >&2
exit 1
fi
fi

View File

@@ -1,4 +1,7 @@
#!/usr/bin/env bash
# Summary: List hook scripts for a given rbenv command
# Usage: rbenv hooks <command>
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -12,7 +15,7 @@ fi
RBENV_COMMAND="$1"
if [ -z "$RBENV_COMMAND" ]; then
echo "usage: rbenv hooks COMMAND" >&2
rbenv-help --usage hooks >&2
exit 1
fi

View File

@@ -1,18 +1,24 @@
#!/usr/bin/env bash
# Summary: Configure the shell environment for rbenv
# Usage: eval "$(rbenv init - [--no-rehash] [<shell>])"
set -e
[ -n "$RBENV_DEBUG" ] && set -x
print=""
if [ "$1" = "-" ]; then
print=1
shift
fi
no_rehash=""
if [ "$1" = "--no-rehash" ]; then
no_rehash=1
shift
fi
for args in "$@"
do
if [ "$args" = "-" ]; then
print=1
shift
fi
if [ "$args" = "--no-rehash" ]; then
no_rehash=1
shift
fi
done
shell="$1"
if [ -z "$shell" ]; then
@@ -79,10 +85,11 @@ if [ -z "$no_rehash" ]; then
echo 'rbenv rehash 2>/dev/null'
fi
commands=(`rbenv commands --sh`)
commands=(`rbenv-commands --sh`)
IFS="|"
cat <<EOS
rbenv() {
typeset command
command="\$1"
if [ "\$#" -gt 0 ]; then
shift

View File

@@ -1,4 +1,28 @@
#!/usr/bin/env bash
#
# Summary: Set or show the local application-specific Ruby version
#
# Usage: rbenv local <version>
# rbenv local --unset
#
# Sets the local application-specific Ruby version by writing the
# version name to a file named `.ruby-version'.
#
# When you run a Ruby command, rbenv will look for a `.ruby-version'
# file in the current directory and each parent directory. If no such
# file is found in the tree, rbenv will use the global Ruby version
# specified with `rbenv global'. A version specified with the
# `RBENV_VERSION' environment variable takes precedence over local
# and global versions.
#
# For backwards compatibility, rbenv will also read version
# specifications from `.rbenv-version' files, but a `.ruby-version'
# file in the same directory takes precedence.
#
# <version> should be a string matching a Ruby version known to rbenv.
# The special version string `system' will use your default system Ruby.
# Run `rbenv versions' for a list of available Ruby versions.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -10,14 +34,20 @@ if [ "$1" = "--complete" ]; then
fi
RBENV_VERSION="$1"
RBENV_VERSION_FILE=".rbenv-version"
if [ "$RBENV_VERSION" = "--unset" ]; then
rm -f "$RBENV_VERSION_FILE"
rm -f .ruby-version .rbenv-version
elif [ -n "$RBENV_VERSION" ]; then
rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION"
if [ "$(RBENV_VERSION= rbenv-version-origin)" -ef .rbenv-version ]; then
rm -f .rbenv-version
{ echo "rbenv: removed existing \`.rbenv-version' file and migrated"
echo " local version specification to \`.ruby-version' file"
} >&2
fi
rbenv-version-file-write .ruby-version "$RBENV_VERSION"
else
rbenv-version-file-read "$RBENV_VERSION_FILE" ||
rbenv-version-file-read .ruby-version ||
rbenv-version-file-read .rbenv-version ||
{ echo "rbenv: no local version configured for this directory"
exit 1
} >&2

View File

@@ -1,4 +1,11 @@
#!/usr/bin/env bash
# Summary: Display prefix for a Ruby version
# Usage: rbenv prefix [<version>]
#
# Displays the directory where a Ruby version is installed. If no
# version is given, `rbenv prefix' displays the location of the
# currently selected version.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -16,7 +23,8 @@ fi
if [ "$RBENV_VERSION" = "system" ]; then
RUBY_PATH="$(rbenv-which ruby)"
echo "${RUBY_PATH%/*}"
RUBY_PATH="${RUBY_PATH%/*}"
echo "${RUBY_PATH%/bin}"
exit
fi

View File

@@ -1,4 +1,6 @@
#!/usr/bin/env bash
# Summary: Rehash rbenv shims (run this after installing executables)
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -30,19 +32,48 @@ remove_prototype_shim() {
# The prototype shim file is a script that re-execs itself, passing
# its filename and any arguments to `rbenv 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.
# hard-linked for every executable 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" <<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 "$(command -v 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.
@@ -55,58 +86,27 @@ make_shims() {
done
}
# Create an empty array for the list of registered shims.
# Create an empty array for the list of registered shims and an empty
# string to use as a search index.
registered_shims=()
registered_shims_index=""
# 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.
# global `reigstered_shims` array and with a global search index
# string. The array will let us iterate over all registered shims. The
# index string 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"
registered_shims["${#registered_shims[@]}"]="$shim"
registered_shims_index="$registered_shims_index/$shim/"
}
# 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() {
local shim
for shim in "${registered_shims[@]}"; do
[ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
done
@@ -117,20 +117,23 @@ install_registered_shims() {
# in the directory but has not been registered as a shim should be
# removed.
remove_stale_shims() {
local var
local shim
for shim in *; do
var="$(shim_variable_name "$shim")"
[ -z "${!var}" ] && rm -f "$shim"
if [[ "$registered_shims_index" != *"/$shim/"* ]]; then
rm -f "$shim"
fi
done
}
# Change to the shims directory.
cd "$SHIM_PATH"
# Create the prototype shim, then register shims for all known binaries.
create_prototype_shim
shopt -s nullglob
# Create the prototype shim, then register shims for all known
# executables.
create_prototype_shim
remove_outdated_shims
make_shims ../versions/*/bin/*
# Restore the previous working directory.

View File

@@ -1,2 +1,3 @@
#!/usr/bin/env bash
# Summary: Display the root directory where versions and shims are kept
echo $RBENV_ROOT

13
libexec/rbenv-sh-rehash Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
exec rbenv-rehash --complete
fi
# When rbenv shell integration is enabled, delegate to rbenv-rehash,
# then tell the shell to empty its command lookup cache.
rbenv-rehash
echo "hash -r"

View File

@@ -1,4 +1,18 @@
#!/usr/bin/env bash
#
# Summary: Set or show the shell-specific Ruby version
#
# Usage: rbenv shell <version>
# rbenv shell --unset
#
# Sets a shell-specific Ruby version by setting the `RBENV_VERSION'
# environment variable in your shell. This version overrides local
# application-specific versions and the global version.
#
# <version> should be a string matching a Ruby version known to rbenv.
# The special version string `system' will use your default system Ruby.
# Run `rbenv versions' for a list of available Ruby versions.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -23,10 +37,13 @@ fi
if [ "$version" = "--unset" ]; then
echo "unset RBENV_VERSION"
exit 1
exit
fi
# Make sure the specified version is installed.
rbenv-prefix "$version" >/dev/null
echo "export RBENV_VERSION=\"${version}\""
if rbenv-prefix "$version" >/dev/null; then
echo "export RBENV_VERSION=\"${version}\""
else
echo "return 1"
exit 1
fi

View File

@@ -1,4 +1,7 @@
#!/usr/bin/env bash
# Summary: List existing rbenv shims
# Usage: rbenv shims [--short]
set -e
[ -n "$RBENV_DEBUG" ] && set -x

View File

@@ -1,4 +1,10 @@
#!/usr/bin/env bash
# Summary: Show the current Ruby version and its origin
#
# Shows the currently selected Ruby version and how it was
# selected. To obtain only the version string, use `rbenv
# version-name'.
set -e
[ -n "$RBENV_DEBUG" ] && set -x

View File

@@ -1,15 +1,24 @@
#!/usr/bin/env bash
# Summary: Detect the file that sets the current rbenv version
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}/.ruby-version" ]; then
echo "${root}/.ruby-version"
exit
elif [ -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"

View File

@@ -1,12 +1,13 @@
#!/usr/bin/env bash
# Usage: rbenv version-file-read <file>
set -e
[ -n "$RBENV_DEBUG" ] && set -x
VERSION_FILE="$1"
if [ -e "$VERSION_FILE" ]; then
# Read and print the first non-whitespace word from the specified
# version file.
# Read the first non-whitespace word from the specified version file.
# Be careful not to load it whole in case there's something crazy in it.
version=""
while read -a words; do
word="${words[0]}"

View File

@@ -1,4 +1,6 @@
#!/usr/bin/env bash
# Usage: rbenv version-file-write <file> <version>
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -6,7 +8,7 @@ RBENV_VERSION_FILE="$1"
RBENV_VERSION="$2"
if [ -z "$RBENV_VERSION" ] || [ -z "$RBENV_VERSION_FILE" ]; then
echo "usage: rbenv write-version-file FILENAME VERSION" >&2
rbenv-help --usage version-file-write >&2
exit 1
fi

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# Summary: Show the current Ruby version
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -12,10 +13,18 @@ if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then
exit
fi
RBENV_VERSION_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}"
version_exists() {
local version="$1"
[ -d "${RBENV_ROOT}/versions/${version}" ]
}
if [ -d "$RBENV_VERSION_PATH" ]; then
if version_exists "$RBENV_VERSION"; then
echo "$RBENV_VERSION"
elif version_exists "${RBENV_VERSION#ruby-}"; then
{ echo "warning: ignoring extraneous \`ruby-' prefix in version \`${RBENV_VERSION}'"
echo " (set by $(rbenv-version-origin))"
} >&2
echo "${RBENV_VERSION#ruby-}"
else
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
exit 1

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# Summary: Explain how the current Ruby version is set
set -e
[ -n "$RBENV_DEBUG" ] && set -x

View File

@@ -1,27 +1,39 @@
#!/usr/bin/env bash
# Summary: List all Ruby versions available to rbenv
# Usage: rbenv versions [--bare]
#
# Lists all Ruby versions found in `$RBENV_ROOT/versions/*'.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
RBENV_VERSION_NAME="$(rbenv-version-name)"
if [ "$1" = "--bare" ]; then
hit_prefix=""
miss_prefix=""
print_version="$RBENV_VERSION_NAME"
current_version=""
include_system=""
else
hit_prefix="* "
miss_prefix=" "
print_version="$(rbenv-version)"
current_version="$(rbenv-version-name || true)"
include_system="1"
fi
print_version() {
if [ "$1" == "$current_version" ]; then
echo "${hit_prefix}$(rbenv-version 2>/dev/null)"
else
echo "${miss_prefix}$1"
fi
}
# Include "system" in the non-bare output, if it exists
if [ -n "$include_system" ] && RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then
print_version system
fi
for path in "${RBENV_ROOT}/versions/"*; do
if [ -d "$path" ]; then
version="${path##*/}"
if [ "$version" == "$RBENV_VERSION_NAME" ]; then
echo "${hit_prefix}${print_version}"
else
echo "${miss_prefix}${version}"
fi
print_version "${path##*/}"
fi
done

View File

@@ -1,4 +1,7 @@
#!/usr/bin/env bash
# Summary: List all Ruby versions that contain the given executable
# Usage: rbenv whence [--path] <command>
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -27,7 +30,7 @@ whence() {
RBENV_COMMAND="$1"
if [ -z "$RBENV_COMMAND" ]; then
echo "usage: rbenv whence [--path] COMMAND" >&2
rbenv-help --usage whence >&2
exit 1
fi

View File

@@ -1,4 +1,12 @@
#!/usr/bin/env bash
#
# Summary: Display the full path to an executable
#
# Usage: rbenv which <command>
#
# Displays the full path to the executable that rbenv will invoke when
# you run the given command.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
@@ -27,7 +35,10 @@ remove_from_path() {
return
fi
for path in ${PATH//:/$'\n'}; do
local paths
IFS=: paths=($PATH)
for path in "${paths[@]}"; do
path="$(expand_path "$path" || true)"
if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then
result="${result}${path}:"
@@ -41,13 +52,13 @@ RBENV_VERSION="$(rbenv-version-name)"
RBENV_COMMAND="$1"
if [ -z "$RBENV_COMMAND" ]; then
echo "usage: rbenv which COMMAND" >&2
rbenv-help --usage which >&2
exit 1
fi
if [ "$RBENV_VERSION" = "system" ]; then
PATH="$(remove_from_path "${RBENV_ROOT}/shims")"
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND")"
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)"
else
RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}"
fi