mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-08 11:33:49 -05:00
Compare commits
242 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bac268cdb | ||
|
|
19fa774e42 | ||
|
|
af03af9593 | ||
|
|
1fcb988164 | ||
|
|
925e5ad0e7 | ||
|
|
35960ee19e | ||
|
|
c3ba994ec2 | ||
|
|
a3b98a4223 | ||
|
|
ac020225c2 | ||
|
|
f2ac882579 | ||
|
|
e8b7a27ee6 | ||
|
|
8d0ca21451 | ||
|
|
d7a5e87d75 | ||
|
|
5cae73944f | ||
|
|
325abac17d | ||
|
|
d10388a052 | ||
|
|
7c4350edf4 | ||
|
|
d6bb1c6396 | ||
|
|
ad6544409b | ||
|
|
ae8a0ee125 | ||
|
|
3646eb840b | ||
|
|
6e58140657 | ||
|
|
a7e508fcdf | ||
|
|
d1f1865c2a | ||
|
|
86b5797083 | ||
|
|
5d78e47399 | ||
|
|
59acc42647 | ||
|
|
4fec76f267 | ||
|
|
592fe6a087 | ||
|
|
906a6acc10 | ||
|
|
3112172081 | ||
|
|
cfe1c37d26 | ||
|
|
af9201ea1e | ||
|
|
56512aee3b | ||
|
|
e390b228c8 | ||
|
|
a632465cf4 | ||
|
|
54744db05e | ||
|
|
dd79c11f6c | ||
|
|
0704e65781 | ||
|
|
8644fb5519 | ||
|
|
41e242857e | ||
|
|
6f21f76965 | ||
|
|
8be1b9bd0e | ||
|
|
7eafc5fe02 | ||
|
|
9fe4cb8e1e | ||
|
|
61747c06d4 | ||
|
|
7509eafdd0 | ||
|
|
593f820a7d | ||
|
|
5c12600625 | ||
|
|
6717c62dc1 | ||
|
|
5f9c0ba613 | ||
|
|
52acbdf83f | ||
|
|
85f304ef3b | ||
|
|
41580b69db | ||
|
|
3e5347be1e | ||
|
|
172a79e993 | ||
|
|
8275e15cb0 | ||
|
|
90c0357682 | ||
|
|
30aaf4edba | ||
|
|
d97713d1b5 | ||
|
|
43e30ef815 | ||
|
|
6b1cc34610 | ||
|
|
d2d3012f17 | ||
|
|
410e05bf8c | ||
|
|
a6cf6aeadb | ||
|
|
8406a2bc7f | ||
|
|
ed1a3a5545 | ||
|
|
22ee5d4175 | ||
|
|
7c7c4dc11c | ||
|
|
45ae8d2ebc | ||
|
|
396e65a461 | ||
|
|
959968c46d | ||
|
|
009ef3a2db | ||
|
|
acdd8a95bd | ||
|
|
98412dba80 | ||
|
|
6426f852d0 | ||
|
|
33f8621ec8 | ||
|
|
9572edf4bb | ||
|
|
117a381575 | ||
|
|
56a440e4a7 | ||
|
|
a8ecfc743e | ||
|
|
c4395e5820 | ||
|
|
a54b47e783 | ||
|
|
c6cc0a1959 | ||
|
|
b39d4291be | ||
|
|
cec6d46792 | ||
|
|
e4f61e67e2 | ||
|
|
42aa760e2e | ||
|
|
d2c527cdd7 | ||
|
|
a76c4aaafa | ||
|
|
5b5c60fb6e | ||
|
|
304cb7b6a7 | ||
|
|
25fdc1caf9 | ||
|
|
264cb65a1e | ||
|
|
00d93c1d91 | ||
|
|
68fca03bb8 | ||
|
|
6cc7bff383 | ||
|
|
38e1fbb08e | ||
|
|
69323e77cc | ||
|
|
526f2de13d | ||
|
|
28cd6f123e | ||
|
|
d3d4606d2f | ||
|
|
0767d64344 | ||
|
|
76e64ff2ea | ||
|
|
b0fb351419 | ||
|
|
e7fd07dd91 | ||
|
|
faf999211b | ||
|
|
585ed84283 | ||
|
|
d061cb4651 | ||
|
|
059bb2c151 | ||
|
|
b904ea54cc | ||
|
|
dcba8b4064 | ||
|
|
633436706f | ||
|
|
4092eba274 | ||
|
|
064e1c48ba | ||
|
|
462bb67709 | ||
|
|
b424d452d0 | ||
|
|
80af359232 | ||
|
|
ccb4601f3a | ||
|
|
5d6f998c52 | ||
|
|
6b842a7670 | ||
|
|
45951d2cbb | ||
|
|
d604acb78a | ||
|
|
37405c3249 | ||
|
|
268c61a69c | ||
|
|
b5429624c2 | ||
|
|
5f7597e754 | ||
|
|
62d7798270 | ||
|
|
4086bbe562 | ||
|
|
60c9339685 | ||
|
|
d3f8de4c04 | ||
|
|
0843745be9 | ||
|
|
d4d69ed0cd | ||
|
|
0493a33f59 | ||
|
|
8bc71e9161 | ||
|
|
a5a1c4d50d | ||
|
|
c879cb0f2f | ||
|
|
59004d77ed | ||
|
|
c2cfbd1e8b | ||
|
|
a17c5fb596 | ||
|
|
c6324ff45a | ||
|
|
74c2486a2c | ||
|
|
ac5dce9014 | ||
|
|
19ae300eb8 | ||
|
|
e429cc0bd8 | ||
|
|
d58cf6ec71 | ||
|
|
143b2c9c02 | ||
|
|
f977248086 | ||
|
|
569d464d36 | ||
|
|
7795476af1 | ||
|
|
137e705db7 | ||
|
|
302797ba41 | ||
|
|
40db754168 | ||
|
|
5c3268c9af | ||
|
|
dd86f543fc | ||
|
|
c46a970595 | ||
|
|
8bb5b1607e | ||
|
|
cc9726c641 | ||
|
|
a574a74042 | ||
|
|
0c3967aa32 | ||
|
|
af454a32dc | ||
|
|
d38d18ec25 | ||
|
|
577f04653d | ||
|
|
8ebf088360 | ||
|
|
4e923221ce | ||
|
|
370c26a6c9 | ||
|
|
a3fa9b73b8 | ||
|
|
483e7f9bdf | ||
|
|
ae2e7a3f0b | ||
|
|
59785f6762 | ||
|
|
806f3f6ae2 | ||
|
|
1c772d5ff2 | ||
|
|
8103febc62 | ||
|
|
8b18b962a3 | ||
|
|
199e598351 | ||
|
|
e55e3c05eb | ||
|
|
bc1b66250f | ||
|
|
dfba9f7608 | ||
|
|
c8ba27fd07 | ||
|
|
9daf81f16e | ||
|
|
b943955dbf | ||
|
|
643023d98f | ||
|
|
af53c790cc | ||
|
|
6aa70b6541 | ||
|
|
5f8a4c4d62 | ||
|
|
eda952ab08 | ||
|
|
b80ea43e25 | ||
|
|
c310bc5f83 | ||
|
|
eab68688dc | ||
|
|
5183e32887 | ||
|
|
e2f469a7cd | ||
|
|
33a5c2495d | ||
|
|
66b9f6fb2b | ||
|
|
a9ca72ab8e | ||
|
|
1a8b5e04a9 | ||
|
|
2d7cefe782 | ||
|
|
650c9d3452 | ||
|
|
4ebd1bd12c | ||
|
|
dbaa8c83b6 | ||
|
|
fb9130e85a | ||
|
|
615f8443fe | ||
|
|
fc706daf60 | ||
|
|
6cd487db81 | ||
|
|
e3e99cc906 | ||
|
|
95b1b05cbe | ||
|
|
755c820724 | ||
|
|
b4330a48b1 | ||
|
|
a81da8d864 | ||
|
|
4e27113494 | ||
|
|
be2e606fbd | ||
|
|
9d93605e18 | ||
|
|
1f1e291385 | ||
|
|
db39044ef6 | ||
|
|
fab5cf912f | ||
|
|
9f52b56aa8 | ||
|
|
4f8925abe7 | ||
|
|
8eb97549e1 | ||
|
|
e60ad4a090 | ||
|
|
6ced4e25de | ||
|
|
2207c27cb4 | ||
|
|
c4d97ad392 | ||
|
|
1b751261ce | ||
|
|
c7dcaf1259 | ||
|
|
d0779fc8fb | ||
|
|
99342d642f | ||
|
|
0c7224af95 | ||
|
|
36138f4901 | ||
|
|
83e874a165 | ||
|
|
8eefa41a4d | ||
|
|
57a902f36a | ||
|
|
07fd1ae66b | ||
|
|
a456528be8 | ||
|
|
6030ea51e4 | ||
|
|
2485257424 | ||
|
|
26ac59fd1d | ||
|
|
7860ad5268 | ||
|
|
9fdce5d069 | ||
|
|
d246e20764 | ||
|
|
121159c089 | ||
|
|
8b0b51a166 | ||
|
|
b81f0a2c42 | ||
|
|
6a912bf104 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/share/man/man[1-8]/*.[1-8] linguist-generated
|
||||||
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: 'github-actions'
|
||||||
|
directory: '/'
|
||||||
|
schedule:
|
||||||
|
interval: 'weekly'
|
||||||
17
.github/workflows/ci.yml
vendored
Normal file
17
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
name: CI
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Install bats
|
||||||
|
run: git clone --depth 1 --branch v1.10.0 https://github.com/bats-core/bats-core.git bats
|
||||||
|
- name: Run tests
|
||||||
|
run: PATH="./bats/bin:$PATH" test/run
|
||||||
29
.github/workflows/lint.yml
vendored
Normal file
29
.github/workflows/lint.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
name: Lint
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
pull_request:
|
||||||
|
branches: [master]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
shellcheck:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Repository checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Differential ShellCheck
|
||||||
|
uses: redhat-plumbers-in-action/differential-shellcheck@v5
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
16
.github/workflows/release.yml
vendored
Normal file
16
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
name: Release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
homebrew:
|
||||||
|
name: Bump Homebrew formula
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: mislav/bump-homebrew-formula-action@v3.1
|
||||||
|
if: "!contains(github.ref, '-')" # skip prereleases
|
||||||
|
with:
|
||||||
|
formula-name: rbenv
|
||||||
|
env:
|
||||||
|
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
sudo: false
|
|
||||||
install: git clone --depth 1 https://github.com/sstephenson/bats.git
|
|
||||||
script: PATH="./bats/bin:$PATH" test/run
|
|
||||||
language: c
|
|
||||||
env:
|
|
||||||
- RBENV_NATIVE_EXT=
|
|
||||||
- RBENV_NATIVE_EXT=1
|
|
||||||
4
Makefile
Normal file
4
Makefile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
release_version := $(shell git describe --tags)
|
||||||
|
|
||||||
|
share/man/man1/rbenv.1: share/man/man1/rbenv.1.adoc
|
||||||
|
asciidoctor -b manpage -a version=$(release_version:v%=%) $<
|
||||||
544
README.md
544
README.md
@@ -1,317 +1,161 @@
|
|||||||
# Groom your app’s Ruby environment with rbenv.
|
# Seamlessly manage your app’s Ruby environment with rbenv.
|
||||||
|
|
||||||
Use rbenv to pick a Ruby version for your application and guarantee
|
rbenv is a version manager tool for the Ruby programming language on Unix-like systems. It is useful for switching between multiple Ruby versions on the same machine and for ensuring that each project you are working on always runs on the correct Ruby version.
|
||||||
that your development environment matches production. Put rbenv to work
|
|
||||||
with [Bundler](http://bundler.io/) for painless Ruby upgrades and
|
|
||||||
bulletproof deployments.
|
|
||||||
|
|
||||||
**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.
|
|
||||||
|
|
||||||
**Rock-solid in production.** Your application's executables are its
|
|
||||||
interface with ops. With rbenv and [Bundler
|
|
||||||
binstubs](https://github.com/rbenv/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.
|
|
||||||
|
|
||||||
**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][]
|
|
||||||
plugin to automate the process. Specify per-application environment
|
|
||||||
variables with [rbenv-vars](https://github.com/rbenv/rbenv-vars).
|
|
||||||
See more [plugins on the
|
|
||||||
wiki](https://github.com/rbenv/rbenv/wiki/Plugins).
|
|
||||||
|
|
||||||
[**Why choose rbenv over
|
|
||||||
RVM?**](https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F)
|
|
||||||
|
|
||||||
## Table of Contents
|
|
||||||
|
|
||||||
* [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)
|
|
||||||
* [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell)
|
|
||||||
* [Installing Ruby versions](#installing-ruby-versions)
|
|
||||||
* [Installing Ruby gems](#installing-ruby-gems)
|
|
||||||
* [Uninstalling Ruby versions](#uninstalling-ruby-versions)
|
|
||||||
* [Uninstalling rbenv](#uninstalling-rbenv)
|
|
||||||
* [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)
|
|
||||||
* [Environment variables](#environment-variables)
|
|
||||||
* [Development](#development)
|
|
||||||
|
|
||||||
## How It Works
|
## How It Works
|
||||||
|
|
||||||
At a high level, rbenv intercepts Ruby commands using shim
|
After rbenv injects itself into your PATH at installation time, any invocation of `ruby`, `gem`, `bundler`, or other Ruby-related executable will first activate rbenv. Then, rbenv scans the current project directory for a file named `.ruby-version`. If found, that file determines the version of Ruby that should be used within that directory. Finally, rbenv looks up that Ruby version among those installed under `~/.rbenv/versions/`.
|
||||||
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.
|
|
||||||
|
|
||||||
### Understanding PATH
|
You can choose the Ruby version for your project with, for example:
|
||||||
|
```sh
|
||||||
|
cd myproject
|
||||||
|
# choose Ruby version 3.1.2:
|
||||||
|
rbenv local 3.1.2
|
||||||
|
```
|
||||||
|
|
||||||
When you run a command like `ruby` or `rake`, your operating system
|
Doing so will create or update the `.ruby-version` file in the current directory with the version that you've chosen. A different project of yours that is another directory might be using a different version of Ruby altogether—rbenv will seamlessly transition from one Ruby version to another when you switch projects.
|
||||||
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:
|
|
||||||
|
|
||||||
/usr/local/bin:/usr/bin:/bin
|
Finally, almost every aspect of rbenv's mechanism is [customizable via plugins][plugins] written in bash.
|
||||||
|
|
||||||
Directories in `PATH` are searched from left to right, so a matching
|
The simplicity of rbenv has its benefits, but also some downsides. See the [comparison of version managers][alternatives] for more details and some alternatives.
|
||||||
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`.
|
|
||||||
|
|
||||||
### Understanding Shims
|
|
||||||
|
|
||||||
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 first `.ruby-version` file found by searching the directory of the
|
|
||||||
script you are executing and each of its parent directories until reaching
|
|
||||||
the root of your filesystem.
|
|
||||||
|
|
||||||
3. The first `.ruby-version` file found by searching the current working
|
|
||||||
directory and each of its parent directories until reaching the root of your
|
|
||||||
filesystem. You can modify the `.ruby-version` file in the current working
|
|
||||||
directory with the [`rbenv local`](#rbenv-local) command.
|
|
||||||
|
|
||||||
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
|
## Installation
|
||||||
|
|
||||||
**Compatibility note**: rbenv is _incompatible_ with RVM. Please make
|
On systems with Homebrew package manager, the “Using Package Managers” method is recommended. On other systems, “Basic Git Checkout” might be the easiest way of ensuring that you are always installing the latest version of rbenv.
|
||||||
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
|
### Using Package Managers
|
||||||
[installing with Homebrew](#homebrew-on-mac-os-x).
|
|
||||||
|
|
||||||
### Basic GitHub Checkout
|
1. Install rbenv using one of the following approaches.
|
||||||
|
|
||||||
This will get you going with the latest version of rbenv and make it
|
#### Homebrew
|
||||||
easy to fork and contribute any changes back upstream.
|
|
||||||
|
On macOS or Linux, we recommend installing rbenv with [Homebrew](https://brew.sh).
|
||||||
|
|
||||||
|
```sh
|
||||||
|
brew install rbenv
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Debian, Ubuntu, and their derivatives
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
> The version of rbenv that is packaged and maintained in official
|
||||||
|
Debian and Ubuntu repositories is _out of date_. To install the latest
|
||||||
|
version, it is recommended to [install rbenv using git](#basic-git-checkout).
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo apt install rbenv
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Arch Linux and its derivatives
|
||||||
|
|
||||||
|
Archlinux has an [AUR Package](https://aur.archlinux.org/packages/rbenv/) for
|
||||||
|
rbenv and you can install it from the AUR using the instructions from this
|
||||||
|
[wiki page](https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_and_upgrading_packages).
|
||||||
|
|
||||||
1. Check out rbenv into `~/.rbenv`.
|
2. Set up your shell to load rbenv.
|
||||||
|
|
||||||
~~~ sh
|
```sh
|
||||||
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
|
rbenv init
|
||||||
~~~
|
```
|
||||||
|
|
||||||
Optionally, try to compile dynamic bash extension to speed up rbenv. Don't
|
3. Close your Terminal window and open a new one so your changes take effect.
|
||||||
worry if it fails; rbenv will still work normally:
|
|
||||||
|
|
||||||
~~~
|
That's it! You are now ready to [install some Ruby versions](#installing-ruby-versions).
|
||||||
$ cd ~/.rbenv && src/configure && make -C src
|
|
||||||
~~~
|
|
||||||
|
|
||||||
2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
|
### Basic Git Checkout
|
||||||
command-line utility.
|
|
||||||
|
|
||||||
~~~ sh
|
> [!NOTE]
|
||||||
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
|
> For a more automated install, you can use [rbenv-installer](https://github.com/rbenv/rbenv-installer#rbenv-installer). If you do not want to execute scripts downloaded from a web URL or simply prefer a manual approach, follow the steps below.
|
||||||
~~~
|
|
||||||
|
|
||||||
**Ubuntu Desktop note**: Modify your `~/.bashrc` instead of `~/.bash_profile`.
|
This will get you going with the latest version of rbenv without needing a system-wide install.
|
||||||
|
|
||||||
**Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`.
|
1. Clone rbenv into `~/.rbenv`.
|
||||||
|
|
||||||
3. Run `~/.rbenv/bin/rbenv init` for shell-specific instructions on how to
|
```sh
|
||||||
initialize rbenv to enable shims and autocompletion.
|
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
|
||||||
|
```
|
||||||
|
|
||||||
4. Restart your shell so that PATH changes take effect. (Opening a new
|
2. Set up your shell to load rbenv.
|
||||||
terminal tab will usually do it.) Now check if rbenv was set up:
|
|
||||||
|
|
||||||
~~~ sh
|
```sh
|
||||||
$ type rbenv
|
~/.rbenv/bin/rbenv init
|
||||||
#=> "rbenv is a function"
|
```
|
||||||
~~~
|
|
||||||
|
|
||||||
5. _(Optional)_ Install [ruby-build][], which provides the
|
If you are curious, see here to [understand what `init` does](#how-rbenv-hooks-into-your-shell).
|
||||||
`rbenv install` command that simplifies the process of
|
|
||||||
[installing new Ruby versions](#installing-ruby-versions).
|
|
||||||
|
|
||||||
#### Upgrading
|
3. Restart your shell so that these changes take effect. (Opening a new terminal tab will usually do it.)
|
||||||
|
|
||||||
If you've installed rbenv manually using git, you can upgrade your
|
#### Shell completions
|
||||||
installation to the cutting-edge version at any time.
|
|
||||||
|
|
||||||
~~~ sh
|
When _manually_ installing rbenv, it might be useful to note how completion scripts for various shells work. Completion scripts help with typing rbenv commands by expanding partially entered rbenv command names and option flags; typically this is invoked by pressing <kbd>Tab</kbd> key in an interactive shell.
|
||||||
$ cd ~/.rbenv
|
|
||||||
$ git pull
|
|
||||||
~~~
|
|
||||||
|
|
||||||
To use a specific release of rbenv, check out the corresponding tag:
|
- The **bash** completion script for rbenv ships with the project and gets [loaded by the `rbenv init` mechanism](#how-rbenv-hooks-into-your-shell).
|
||||||
|
|
||||||
~~~ sh
|
- The **zsh** completion script ships with the project, but needs to be added to FPATH in zsh before it can be discovered by the shell. One way to do this would be to edit `~/.zshrc`:
|
||||||
$ cd ~/.rbenv
|
|
||||||
$ git fetch
|
|
||||||
$ git checkout v0.3.0
|
|
||||||
~~~
|
|
||||||
|
|
||||||
If you've [installed via Homebrew](#homebrew-on-mac-os-x), then upgrade
|
```sh
|
||||||
via its `brew` command:
|
# assuming that rbenv was installed to `~/.rbenv`
|
||||||
|
FPATH=~/.rbenv/completions:"$FPATH"
|
||||||
|
|
||||||
~~~ sh
|
autoload -U compinit
|
||||||
$ brew update
|
compinit
|
||||||
$ brew upgrade rbenv ruby-build
|
```
|
||||||
~~~
|
|
||||||
|
|
||||||
### Homebrew on Mac OS X
|
- The **fish** completion script for rbenv ships with the fish shell itself and is not maintained by the rbenv project.
|
||||||
|
|
||||||
As an alternative to installation via GitHub checkout, you can install
|
|
||||||
rbenv and [ruby-build][] using the [Homebrew](http://brew.sh) package
|
|
||||||
manager on Mac OS X:
|
|
||||||
|
|
||||||
~~~
|
|
||||||
$ brew update
|
|
||||||
$ brew install rbenv
|
|
||||||
~~~
|
|
||||||
|
|
||||||
Afterwards you'll still need to run `rbenv init` for instructions
|
|
||||||
as stated in the caveats. You'll only ever have to do this once.
|
|
||||||
|
|
||||||
### How rbenv hooks into your shell
|
|
||||||
|
|
||||||
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 automatically 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.
|
|
||||||
|
|
||||||
### Installing Ruby versions
|
### Installing Ruby versions
|
||||||
|
|
||||||
The `rbenv install` command doesn't ship with rbenv out of the box, but
|
The `rbenv install` command does not ship with rbenv out-of-the-box, but is provided by the [ruby-build][] plugin.
|
||||||
is provided by the [ruby-build][] project. If you installed it either
|
|
||||||
as part of GitHub checkout process outlined above or via Homebrew, you
|
|
||||||
should be able to:
|
|
||||||
|
|
||||||
~~~ sh
|
Before attempting to install Ruby, **check that [your build environment](https://github.com/rbenv/ruby-build/wiki#suggested-build-environment) has the necessary tools and libraries**. Then:
|
||||||
# list all available versions:
|
|
||||||
$ rbenv install -l
|
```sh
|
||||||
|
# list latest stable versions:
|
||||||
|
rbenv install -l
|
||||||
|
|
||||||
|
# list all local versions:
|
||||||
|
rbenv install -L
|
||||||
|
|
||||||
# install a Ruby version:
|
# install a Ruby version:
|
||||||
$ rbenv install 2.0.0-p247
|
rbenv install 3.1.2
|
||||||
~~~
|
```
|
||||||
|
|
||||||
Alternatively to the `install` command, you can download and compile
|
For troubleshooting `BUILD FAILED` scenarios, check the [ruby-build Discussions section](https://github.com/rbenv/ruby-build/discussions/categories/build-failures).
|
||||||
Ruby manually as a subdirectory of `~/.rbenv/versions/`. An entry in
|
|
||||||
that directory can also be a symlink to a Ruby version installed
|
> [!NOTE]
|
||||||
elsewhere on the filesystem. rbenv doesn't care; it will simply treat
|
> If the `rbenv install` command wasn't found, you can install ruby-build as a plugin:
|
||||||
any entry in the `versions/` directory as a separate Ruby version.
|
> ```sh
|
||||||
|
> git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
|
||||||
|
> ```
|
||||||
|
|
||||||
|
Set a Ruby version to finish installation and start using Ruby:
|
||||||
|
```sh
|
||||||
|
rbenv global 3.1.2 # set the default Ruby version for this machine
|
||||||
|
# or:
|
||||||
|
rbenv local 3.1.2 # set the Ruby version for this directory
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively to the `rbenv install` command, you can download and compile Ruby manually as a subdirectory of `~/.rbenv/versions`. An entry in that directory can also be a symlink to a Ruby version installed elsewhere on the filesystem.
|
||||||
|
|
||||||
#### Installing Ruby gems
|
#### Installing Ruby gems
|
||||||
|
|
||||||
Once you've installed some Ruby versions, you'll want to install gems.
|
Select a Ruby version for your project using `rbenv local 3.1.2`, for example. Then, proceed to install gems as you normally would:
|
||||||
First, ensure that the target version for your project is the one you want by
|
|
||||||
checking `rbenv version` (see [Command Reference](#command-reference)). Select
|
|
||||||
another version using `rbenv local 2.0.0-p247`, for example. Then, proceed to
|
|
||||||
install gems as you normally would:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ gem install bundler
|
gem install bundler
|
||||||
```
|
```
|
||||||
|
|
||||||
**You don't need sudo** to install gems. Typically, the Ruby versions will be
|
> [!NOTE]
|
||||||
installed and writeable by your user. No extra privileges are required to
|
> You _should not use sudo_ to install gems. Typically, the Ruby versions will be installed under your home directory and thus writeable by your user. If you get the “you don't have write permissions” error when installing gems, it's likely that your "system" Ruby version is still a global default. Change that with `rbenv global <version>` and try again.
|
||||||
install gems.
|
|
||||||
|
|
||||||
Check the location where gems are being installed with `gem env`:
|
Check the location where gems are being installed with `gem env`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ gem env home
|
gem env home
|
||||||
# => ~/.rbenv/versions/<ruby-version>/lib/ruby/gems/...
|
# => ~/.rbenv/versions/<version>/lib/ruby/gems/...
|
||||||
```
|
```
|
||||||
|
|
||||||
### Uninstalling Ruby versions
|
#### Uninstalling Ruby versions
|
||||||
|
|
||||||
As time goes on, Ruby versions you install will accumulate in your
|
As time goes on, Ruby versions you install will accumulate in your
|
||||||
`~/.rbenv/versions` directory.
|
`~/.rbenv/versions` directory.
|
||||||
@@ -319,89 +163,14 @@ As time goes on, Ruby versions you install will accumulate in your
|
|||||||
To remove old Ruby versions, simply `rm -rf` the directory of the
|
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
|
version you want to remove. You can find the directory of a particular
|
||||||
Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix
|
Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix
|
||||||
1.8.7-p357`.
|
2.7.0`.
|
||||||
|
|
||||||
The [ruby-build][] plugin provides an `rbenv uninstall` command to
|
The [ruby-build][] plugin provides an `rbenv uninstall` command to
|
||||||
automate the removal process.
|
automate the removal process.
|
||||||
|
|
||||||
### Uninstalling rbenv
|
|
||||||
|
|
||||||
The simplicity of rbenv makes it easy to temporarily disable it, or
|
|
||||||
uninstall from the system.
|
|
||||||
|
|
||||||
1. To **disable** rbenv managing your Ruby versions, simply remove the
|
|
||||||
`rbenv init` line from your shell startup configuration. This will
|
|
||||||
remove rbenv shims directory from PATH, and future invocations like
|
|
||||||
`ruby` will execute the system Ruby version, as before rbenv.
|
|
||||||
|
|
||||||
`rbenv` will still be accessible on the command line, but your Ruby
|
|
||||||
apps won't be affected by version switching.
|
|
||||||
|
|
||||||
2. To completely **uninstall** rbenv, perform step (1) and then remove
|
|
||||||
its root directory. This will **delete all Ruby versions** that were
|
|
||||||
installed under `` `rbenv root`/versions/ `` directory:
|
|
||||||
|
|
||||||
rm -rf `rbenv root`
|
|
||||||
|
|
||||||
If you've installed rbenv using a package manager, as a final step
|
|
||||||
perform the rbenv package removal. For instance, for Homebrew:
|
|
||||||
|
|
||||||
brew uninstall rbenv
|
|
||||||
|
|
||||||
## Command Reference
|
## Command Reference
|
||||||
|
|
||||||
Like `git`, the `rbenv` command delegates to subcommands based on its
|
The main rbenv commands you need to know are:
|
||||||
first argument. The most common subcommands are:
|
|
||||||
|
|
||||||
### 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
|
|
||||||
|
|
||||||
### 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 an application-specific `.ruby-version` file, or by
|
|
||||||
setting the `RBENV_VERSION` environment variable.
|
|
||||||
|
|
||||||
$ rbenv global 1.8.7-p352
|
|
||||||
|
|
||||||
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 shell
|
|
||||||
|
|
||||||
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
|
|
||||||
environment variable in your shell. This version overrides
|
|
||||||
application-specific versions and the global version.
|
|
||||||
|
|
||||||
$ 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:
|
|
||||||
|
|
||||||
$ 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.7.1
|
|
||||||
|
|
||||||
### rbenv versions
|
### rbenv versions
|
||||||
|
|
||||||
@@ -424,13 +193,61 @@ how it was set.
|
|||||||
$ rbenv version
|
$ rbenv version
|
||||||
1.9.3-p327 (set by /Users/sam/.rbenv/version)
|
1.9.3-p327 (set by /Users/sam/.rbenv/version)
|
||||||
|
|
||||||
|
### 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 3.1.2
|
||||||
|
|
||||||
|
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 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 an application-specific `.ruby-version` file, or by
|
||||||
|
setting the `RBENV_VERSION` environment variable.
|
||||||
|
|
||||||
|
rbenv global 3.1.2
|
||||||
|
|
||||||
|
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 shell
|
||||||
|
|
||||||
|
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
|
||||||
|
environment variable in your shell. This version overrides
|
||||||
|
application-specific versions and the global version.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
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.7.1
|
||||||
|
|
||||||
### rbenv rehash
|
### rbenv rehash
|
||||||
|
|
||||||
Installs shims for all Ruby executables known to rbenv (i.e.,
|
Installs shims for all Ruby executables known to rbenv (`~/.rbenv/versions/*/bin/*`). Typically you do not need to run this command, as it will run automatically after installing gems.
|
||||||
`~/.rbenv/versions/*/bin/*`). Run this command after you install a new
|
|
||||||
version of Ruby, or install a gem that provides commands.
|
|
||||||
|
|
||||||
$ rbenv rehash
|
rbenv rehash
|
||||||
|
|
||||||
### rbenv which
|
### rbenv which
|
||||||
|
|
||||||
@@ -442,7 +259,7 @@ you run the given command.
|
|||||||
|
|
||||||
### rbenv whence
|
### rbenv whence
|
||||||
|
|
||||||
Lists all Ruby versions with the given command installed.
|
Lists all Ruby versions that contain the specified executable name.
|
||||||
|
|
||||||
$ rbenv whence rackup
|
$ rbenv whence rackup
|
||||||
1.9.3-p327
|
1.9.3-p327
|
||||||
@@ -461,13 +278,44 @@ name | default | description
|
|||||||
`RBENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for rbenv hooks.
|
`RBENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for rbenv hooks.
|
||||||
`RBENV_DIR` | `$PWD` | Directory to start searching for `.ruby-version` files.
|
`RBENV_DIR` | `$PWD` | Directory to start searching for `.ruby-version` files.
|
||||||
|
|
||||||
|
### How rbenv hooks into your shell
|
||||||
|
|
||||||
|
`rbenv init` is a helper command to bootstrap rbenv into a shell. This helper is part of the recommended installation instructions, but optional, as an advanced user can set up the following tasks manually. Here is what the command does when its output is `eval`'d by a shell during its startup:
|
||||||
|
|
||||||
|
0. Adds `rbenv` executable to PATH if necessary.
|
||||||
|
|
||||||
|
1. Prepends `~/.rbenv/shims` directory to PATH. This is basically the only requirement for rbenv to function properly.
|
||||||
|
|
||||||
|
2. Installs bash shell completion for rbenv commands.
|
||||||
|
|
||||||
|
3. Regenerates rbenv shims. If this step slows down your shell startup, you can invoke `rbenv init -` with the `--no-rehash` flag.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
You can run `rbenv init -` for yourself to inspect the generated script.
|
||||||
|
|
||||||
|
### Uninstalling rbenv
|
||||||
|
|
||||||
|
The simplicity of rbenv makes it easy to temporarily disable it, or
|
||||||
|
uninstall from the system.
|
||||||
|
|
||||||
|
1. To **disable** rbenv managing your Ruby versions, simply comment or remove the `rbenv init` line from your shell startup configuration. This will remove rbenv shims directory from PATH, and future invocations like `ruby` will execute the system Ruby version, bypassing rbenv completely.
|
||||||
|
|
||||||
|
While disabled, `rbenv` will still be accessible on the command line, but your Ruby apps won't be affected by version switching.
|
||||||
|
|
||||||
|
2. To completely **uninstall** rbenv, perform step (1) and then remove the rbenv root directory. This will **delete all Ruby versions** that were installed under `` `rbenv root`/versions/ ``:
|
||||||
|
|
||||||
|
rm -rf "$(rbenv root)"
|
||||||
|
|
||||||
|
If you've installed rbenv using a package manager, as a final step
|
||||||
|
perform the rbenv package removal:
|
||||||
|
- Homebrew: `brew uninstall rbenv`
|
||||||
|
- Debian, Ubuntu, and their derivatives: `sudo apt purge rbenv`
|
||||||
|
- Archlinux and its derivatives: `sudo pacman -R rbenv`
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
The rbenv source code is [hosted on
|
Tests are executed using [Bats](https://github.com/bats-core/bats-core):
|
||||||
GitHub](https://github.com/rbenv/rbenv). It's clean, modular,
|
|
||||||
and easy to understand, even if you're not a shell hacker.
|
|
||||||
|
|
||||||
Tests are executed using [Bats](https://github.com/sstephenson/bats):
|
|
||||||
|
|
||||||
$ bats test
|
$ bats test
|
||||||
$ bats test/<file>.bats
|
$ bats test/<file>.bats
|
||||||
@@ -478,3 +326,5 @@ tracker](https://github.com/rbenv/rbenv/issues).
|
|||||||
|
|
||||||
[ruby-build]: https://github.com/rbenv/ruby-build#readme
|
[ruby-build]: https://github.com/rbenv/ruby-build#readme
|
||||||
[hooks]: https://github.com/rbenv/rbenv/wiki/Authoring-plugins#rbenv-hooks
|
[hooks]: https://github.com/rbenv/rbenv/wiki/Authoring-plugins#rbenv-hooks
|
||||||
|
[alternatives]: https://github.com/rbenv/rbenv/wiki/Comparison-of-version-managers
|
||||||
|
[plugins]: https://github.com/rbenv/rbenv/wiki/Plugins
|
||||||
|
|||||||
13
completions/_rbenv
Normal file
13
completions/_rbenv
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#compdef rbenv
|
||||||
|
|
||||||
|
_rbenv() {
|
||||||
|
local completions
|
||||||
|
|
||||||
|
if [ "${#words}" -eq 2 ]; then
|
||||||
|
completions=(${(f)"$(rbenv help --complete-commands "${words[2]}")"})
|
||||||
|
_describe 'rbenv commands' completions
|
||||||
|
else
|
||||||
|
completions="$(rbenv completions ${words[2,-2]})"
|
||||||
|
compadd - "${(ps:\n:)completions}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
@@ -6,8 +6,8 @@ _rbenv() {
|
|||||||
COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") )
|
COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") )
|
||||||
else
|
else
|
||||||
local words=("${COMP_WORDS[@]}")
|
local words=("${COMP_WORDS[@]}")
|
||||||
unset words[0]
|
unset "words[0]"
|
||||||
unset words[$COMP_CWORD]
|
unset "words[$COMP_CWORD]"
|
||||||
local completions=$(rbenv completions "${words[@]}")
|
local completions=$(rbenv completions "${words[@]}")
|
||||||
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
|
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
function __fish_rbenv_needs_command
|
|
||||||
set cmd (commandline -opc)
|
|
||||||
if [ (count $cmd) -eq 1 -a $cmd[1] = 'rbenv' ]
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return 1
|
|
||||||
end
|
|
||||||
|
|
||||||
function __fish_rbenv_using_command
|
|
||||||
set cmd (commandline -opc)
|
|
||||||
if [ (count $cmd) -gt 1 ]
|
|
||||||
if [ $argv[1] = $cmd[2] ]
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return 1
|
|
||||||
end
|
|
||||||
|
|
||||||
complete -f -c rbenv -n '__fish_rbenv_needs_command' -a '(rbenv commands)'
|
|
||||||
for cmd in (rbenv commands)
|
|
||||||
complete -f -c rbenv -n "__fish_rbenv_using_command $cmd" -a "(rbenv completions $cmd)"
|
|
||||||
end
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
if [[ ! -o interactive ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
compctl -K _rbenv rbenv
|
|
||||||
|
|
||||||
_rbenv() {
|
|
||||||
local words completions
|
|
||||||
read -cA words
|
|
||||||
|
|
||||||
if [ "${#words}" -eq 2 ]; then
|
|
||||||
completions="$(rbenv commands)"
|
|
||||||
else
|
|
||||||
completions="$(rbenv completions ${words[2,-2]})"
|
|
||||||
fi
|
|
||||||
|
|
||||||
reply=("${(ps:\n:)completions}")
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
export -n CDPATH
|
|
||||||
|
|
||||||
if [ "$1" = "--debug" ]; then
|
if [ "$1" = "--debug" ]; then
|
||||||
export RBENV_DEBUG=1
|
export RBENV_DEBUG=1
|
||||||
@@ -8,7 +7,8 @@ if [ "$1" = "--debug" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$RBENV_DEBUG" ]; then
|
if [ -n "$RBENV_DEBUG" ]; then
|
||||||
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
|
# https://web.archive.org/web/20221105082147/https://wiki-dev.bash-hackers.org/scripting/debuggingtips#making_xtrace_more_useful
|
||||||
|
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -20,36 +20,6 @@ abort() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
|
|
||||||
abs_dirname() {
|
|
||||||
local path="$(realpath "$1")"
|
|
||||||
echo "${path%/*}"
|
|
||||||
}
|
|
||||||
else
|
|
||||||
[ -z "$RBENV_NATIVE_EXT" ] || abort "failed to load \`realpath' builtin"
|
|
||||||
|
|
||||||
READLINK=$(type -p greadlink readlink | head -1)
|
|
||||||
[ -n "$READLINK" ] || abort "cannot find readlink - are you missing GNU coreutils?"
|
|
||||||
|
|
||||||
resolve_link() {
|
|
||||||
$READLINK "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
abs_dirname() {
|
|
||||||
local cwd="$PWD"
|
|
||||||
local path="$1"
|
|
||||||
|
|
||||||
while [ -n "$path" ]; do
|
|
||||||
cd "${path%/*}"
|
|
||||||
local name="${path##*/}"
|
|
||||||
path="$(resolve_link "$name" || true)"
|
|
||||||
done
|
|
||||||
|
|
||||||
pwd
|
|
||||||
cd "$cwd"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${RBENV_ROOT}" ]; then
|
if [ -z "${RBENV_ROOT}" ]; then
|
||||||
RBENV_ROOT="${HOME}/.rbenv"
|
RBENV_ROOT="${HOME}/.rbenv"
|
||||||
else
|
else
|
||||||
@@ -60,25 +30,57 @@ export RBENV_ROOT
|
|||||||
if [ -z "${RBENV_DIR}" ]; then
|
if [ -z "${RBENV_DIR}" ]; then
|
||||||
RBENV_DIR="$PWD"
|
RBENV_DIR="$PWD"
|
||||||
else
|
else
|
||||||
|
[[ $RBENV_DIR == /* ]] || RBENV_DIR="$PWD/$RBENV_DIR"
|
||||||
cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'"
|
cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'"
|
||||||
RBENV_DIR="$PWD"
|
RBENV_DIR="$PWD"
|
||||||
cd "$OLDPWD"
|
cd "$OLDPWD"
|
||||||
fi
|
fi
|
||||||
export RBENV_DIR
|
export RBENV_DIR
|
||||||
|
|
||||||
|
[ -n "$RBENV_ORIG_PATH" ] || export RBENV_ORIG_PATH="$PATH"
|
||||||
|
|
||||||
|
canonicalize() {
|
||||||
|
local readlink resolved_path
|
||||||
|
if readlink="$(type -P greadlink)" || readlink="$(type -P readlink)"; then
|
||||||
|
# happy path: GNU & BSD readlink, macOS 12.3+
|
||||||
|
if resolved_path="$("$readlink" -f "$1" 2>/dev/null)"; then
|
||||||
|
printf "%s\n" "$resolved_path"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
# likely macOS < 12.3 with old readlink
|
||||||
|
local path="$1"
|
||||||
|
while [ -L "$path" ]; do
|
||||||
|
resolved_path="$("$readlink" "$path" 2>/dev/null)"
|
||||||
|
[[ $resolved_path == /* ]] || resolved_path="$(cd "${path%/*}/${resolved_path%/*}" && pwd)/${resolved_path##*/}"
|
||||||
|
path="$resolved_path"
|
||||||
|
done
|
||||||
|
printf "%s\n" "$path"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
# fail if the argument is a symlink and was not canonicalized
|
||||||
|
[ ! -L "$1" ] || return 1
|
||||||
|
}
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
bin_path="$(abs_dirname "$0")"
|
# all this trouble just to find out where rbenv's executables live
|
||||||
|
rbenv_bin="${BASH_SOURCE:-$0}"
|
||||||
|
if libexec_dir="$(canonicalize "$rbenv_bin")"; then
|
||||||
|
libexec_dir="${libexec_dir%/*}"
|
||||||
|
else
|
||||||
|
libexec_dir="${rbenv_bin%/*}"
|
||||||
|
[ "$libexec_dir" != "." ] || libexec_dir="$PWD"
|
||||||
|
fi
|
||||||
|
|
||||||
for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do
|
for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do
|
||||||
PATH="${plugin_bin}:${PATH}"
|
PATH="${plugin_bin}:${PATH}"
|
||||||
done
|
done
|
||||||
export PATH="${bin_path}:${PATH}"
|
export PATH="${libexec_dir}:${PATH}"
|
||||||
|
|
||||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d"
|
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d"
|
||||||
if [ "${bin_path%/*}" != "$RBENV_ROOT" ]; then
|
if [ ! "${libexec_dir%/*}"/rbenv.d -ef "$RBENV_ROOT"/rbenv.d ]; then
|
||||||
# Add rbenv's own `rbenv.d` unless rbenv was cloned to RBENV_ROOT
|
# Add rbenv's own `rbenv.d` unless rbenv was cloned to RBENV_ROOT
|
||||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${bin_path%/*}/rbenv.d"
|
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${libexec_dir%/*}/rbenv.d"
|
||||||
fi
|
fi
|
||||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
||||||
for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do
|
for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do
|
||||||
@@ -104,12 +106,22 @@ case "$command" in
|
|||||||
exec rbenv-help
|
exec rbenv-help
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
command_path="$(command -v "rbenv-$command" || true)"
|
command_path="$(type -P "rbenv-$command" || true)"
|
||||||
[ -n "$command_path" ] || abort "no such command \`$command'"
|
if [ -z "$command_path" ]; then
|
||||||
|
if [ "$command" == "shell" ]; then
|
||||||
|
abort "shell integration not enabled. Run \`rbenv init' for instructions."
|
||||||
|
else
|
||||||
|
abort "no such command \`$command'"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
shift 1
|
shift 1
|
||||||
if [ "$1" = --help ]; then
|
if [ "$1" = --help ]; then
|
||||||
exec rbenv-help "$command"
|
if [[ "$command" == "sh-"* ]]; then
|
||||||
|
echo "rbenv help \"$command\""
|
||||||
|
else
|
||||||
|
exec rbenv-help "$command"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
exec "$command_path" "$@"
|
exec "$command_path" "$@"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
set -e
|
set -e
|
||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
version="1.0.0"
|
version="1.3.0"
|
||||||
git_revision=""
|
git_revision=""
|
||||||
|
|
||||||
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
|
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Summary: List all available rbenv commands
|
# Summary: List all available rbenv commands
|
||||||
# Usage: rbenv commands [--sh|--no-sh]
|
# Usage: rbenv commands [--sh|--no-sh]
|
||||||
|
#
|
||||||
|
# List names of all rbenv commands, including 3rd-party ones found in the
|
||||||
|
# PATH or in rbenv plugins. With `--sh`, list only shell commands.
|
||||||
|
#
|
||||||
|
# This functionality is mainly meant for scripting. To see usage help for
|
||||||
|
# rbenv, run `rbenv help`.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
@@ -20,7 +26,7 @@ elif [ "$1" = "--no-sh" ]; then
|
|||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
IFS=: paths=($PATH)
|
IFS=: read -d '' -r -a paths <<<"$PATH" || true
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
@@ -28,15 +34,15 @@ shopt -s nullglob
|
|||||||
for command in "${path}/rbenv-"*; do
|
for command in "${path}/rbenv-"*; do
|
||||||
command="${command##*rbenv-}"
|
command="${command##*rbenv-}"
|
||||||
if [ -n "$sh" ]; then
|
if [ -n "$sh" ]; then
|
||||||
if [ ${command:0:3} = "sh-" ]; then
|
if [ "${command:0:3}" = "sh-" ]; then
|
||||||
echo ${command##sh-}
|
echo "${command##sh-}"
|
||||||
fi
|
fi
|
||||||
elif [ -n "$nosh" ]; then
|
elif [ -n "$nosh" ]; then
|
||||||
if [ ${command:0:3} != "sh-" ]; then
|
if [ "${command:0:3}" != "sh-" ]; then
|
||||||
echo ${command##sh-}
|
echo "${command##sh-}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo ${command##sh-}
|
echo "${command##sh-}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Usage: rbenv completions <command> [arg1 arg2...]
|
# Usage: rbenv completions <command> [<args>...]
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
@@ -15,7 +15,7 @@ if [ "$COMMAND" = "--complete" ]; then
|
|||||||
exec rbenv-commands
|
exec rbenv-commands
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")"
|
COMMAND_PATH="$(type -P "rbenv-$COMMAND" "rbenv-sh-$COMMAND" | head -n1)"
|
||||||
|
|
||||||
# --help is provided automatically
|
# --help is provided automatically
|
||||||
echo --help
|
echo --help
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Summary: Run an executable with the selected Ruby version
|
# Summary: Run an executable with the selected Ruby version
|
||||||
#
|
#
|
||||||
# Usage: rbenv exec <command> [arg1 arg2...]
|
# Usage: rbenv exec <command> [<args>...]
|
||||||
#
|
#
|
||||||
# Runs an executable by first preparing PATH so that the selected Ruby
|
# Runs an executable by first preparing PATH so that the selected Ruby
|
||||||
# version's `bin' directory is at the front.
|
# version's `bin' directory is at the front.
|
||||||
@@ -33,10 +33,9 @@ export RBENV_VERSION
|
|||||||
RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")"
|
RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")"
|
||||||
RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}"
|
RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}"
|
||||||
|
|
||||||
OLDIFS="$IFS"
|
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks exec)" || true
|
||||||
IFS=$'\n' scripts=(`rbenv-hooks exec`)
|
|
||||||
IFS="$OLDIFS"
|
|
||||||
for script in "${scripts[@]}"; do
|
for script in "${scripts[@]}"; do
|
||||||
|
# shellcheck disable=SC1090
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ fi
|
|||||||
|
|
||||||
command_path() {
|
command_path() {
|
||||||
local command="$1"
|
local command="$1"
|
||||||
command -v rbenv-"$command" || command -v rbenv-sh-"$command" || true
|
type -P rbenv-"$command" rbenv-sh-"$command" | head -n1
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_initial_comment_block() {
|
extract_initial_comment_block() {
|
||||||
@@ -42,7 +42,15 @@ extract_initial_comment_block() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
collect_documentation() {
|
collect_documentation() {
|
||||||
$(type -p gawk awk | head -1) '
|
local awk
|
||||||
|
awk="$(type -P gawk)" || awk="$(type -P awk)" || true
|
||||||
|
if [ -z "$awk" ]; then
|
||||||
|
echo "rbenv: cannot find awk" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
"$awk" '
|
||||||
/^Summary:/ {
|
/^Summary:/ {
|
||||||
summary = substr($0, 10)
|
summary = substr($0, 10)
|
||||||
next
|
next
|
||||||
@@ -86,7 +94,8 @@ collect_documentation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
documentation_for() {
|
documentation_for() {
|
||||||
local filename="$(command_path "$1")"
|
local filename
|
||||||
|
filename="$(command_path "$1")"
|
||||||
if [ -n "$filename" ]; then
|
if [ -n "$filename" ]; then
|
||||||
extract_initial_comment_block < "$filename" | collect_documentation
|
extract_initial_comment_block < "$filename" | collect_documentation
|
||||||
fi
|
fi
|
||||||
@@ -114,7 +123,7 @@ print_help() {
|
|||||||
eval "$(documentation_for "$command")"
|
eval "$(documentation_for "$command")"
|
||||||
[ -n "$help" ] || help="$summary"
|
[ -n "$help" ] || help="$summary"
|
||||||
|
|
||||||
if [ -n "$usage" -o -n "$summary" ]; then
|
if [ -n "$usage" ] || [ -n "$summary" ]; then
|
||||||
if [ -n "$usage" ]; then
|
if [ -n "$usage" ]; then
|
||||||
echo "$usage"
|
echo "$usage"
|
||||||
else
|
else
|
||||||
@@ -135,9 +144,34 @@ print_usage() {
|
|||||||
local command="$1"
|
local command="$1"
|
||||||
local summary usage help
|
local summary usage help
|
||||||
eval "$(documentation_for "$command")"
|
eval "$(documentation_for "$command")"
|
||||||
[ -z "$usage" ] || echo "$usage"
|
if [ -n "$usage" ]; then
|
||||||
|
echo "$usage"
|
||||||
|
else
|
||||||
|
echo "Usage: rbenv ${command}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if [ "$1" = "--complete-commands" ]; then
|
||||||
|
command_prefix="${2:-}"
|
||||||
|
seen=()
|
||||||
|
IFS=: read -d '' -r -a paths <<<"$PATH" || true
|
||||||
|
shopt -s nullglob
|
||||||
|
for path in "${paths[@]}"; do
|
||||||
|
for command in "${path}/rbenv-${command_prefix}"*; do
|
||||||
|
command_name="${command##*/}"
|
||||||
|
command_name="${command_name#rbenv-}"
|
||||||
|
command_name="${command_name#sh-}"
|
||||||
|
[[ " ${seen[*]} " != *" ${command_name} "* ]] || continue
|
||||||
|
seen+=("$command_name")
|
||||||
|
summary=""
|
||||||
|
eval "$(extract_initial_comment_block < "$command" | collect_documentation)"
|
||||||
|
[ -n "$summary" ] || continue
|
||||||
|
printf "%s:%s\n" "$command_name" "$summary"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
unset usage
|
unset usage
|
||||||
if [ "$1" = "--usage" ]; then
|
if [ "$1" = "--usage" ]; then
|
||||||
usage="1"
|
usage="1"
|
||||||
@@ -145,11 +179,17 @@ if [ "$1" = "--usage" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$1" ] || [ "$1" == "rbenv" ]; then
|
if [ -z "$1" ] || [ "$1" == "rbenv" ]; then
|
||||||
echo "Usage: rbenv <command> [<args>]"
|
if [ -z "$usage" ] && [ -t 1 ] && type -P man >/dev/null; then
|
||||||
[ -z "$usage" ] || exit
|
MANPATH="${BASH_SOURCE%/*}/../share/man:$MANPATH" exec man rbenv
|
||||||
|
fi
|
||||||
|
echo "Usage: rbenv <command> [<args>...]"
|
||||||
|
[ -n "$usage" ] && exit
|
||||||
echo
|
echo
|
||||||
echo "Some useful rbenv commands are:"
|
echo "Commands to manage available Ruby versions:"
|
||||||
print_summaries commands local global shell install uninstall rehash version versions which whence
|
print_summaries versions install uninstall rehash
|
||||||
|
echo
|
||||||
|
echo "Commands to view or change the current Ruby version:"
|
||||||
|
print_summaries version local global shell
|
||||||
echo
|
echo
|
||||||
echo "See \`rbenv help <command>' for information on a specific command."
|
echo "See \`rbenv help <command>' for information on a specific command."
|
||||||
echo "For full documentation, see: https://github.com/rbenv/rbenv#readme"
|
echo "For full documentation, see: https://github.com/rbenv/rbenv#readme"
|
||||||
|
|||||||
@@ -21,43 +21,12 @@ if [ -z "$RBENV_COMMAND" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! enable -f "${BASH_SOURCE%/*}"/rbenv-realpath.dylib realpath 2>/dev/null; then
|
IFS=: read -r -a hook_paths <<<"$RBENV_HOOK_PATH"
|
||||||
if [ -n "$RBENV_NATIVE_EXT" ]; then
|
|
||||||
echo "rbenv: failed to load \`realpath' builtin" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
READLINK=$(type -p greadlink readlink | head -1)
|
|
||||||
if [ -z "$READLINK" ]; then
|
|
||||||
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
resolve_link() {
|
|
||||||
$READLINK "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
realpath() {
|
|
||||||
local cwd="$PWD"
|
|
||||||
local path="$1"
|
|
||||||
local name
|
|
||||||
|
|
||||||
while [ -n "$path" ]; do
|
|
||||||
name="${path##*/}"
|
|
||||||
[ "$name" = "$path" ] || cd "${path%/*}"
|
|
||||||
path="$(resolve_link "$name" || true)"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "${PWD}/$name"
|
|
||||||
cd "$cwd"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
IFS=: hook_paths=($RBENV_HOOK_PATH)
|
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
for path in "${hook_paths[@]}"; do
|
for path in "${hook_paths[@]}"; do
|
||||||
for script in "$path/$RBENV_COMMAND"/*.bash; do
|
for script in "$path/$RBENV_COMMAND"/*.bash; do
|
||||||
realpath "$script"
|
echo "$script"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
shopt -u nullglob
|
shopt -u nullglob
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Summary: Configure the shell environment for rbenv
|
# Summary: Configure the shell environment for rbenv
|
||||||
# Usage: eval "$(rbenv init - [--no-rehash] [<shell>])"
|
# Usage: rbenv init [<shells>...]
|
||||||
|
# rbenv init - [--no-rehash] [<shell>]
|
||||||
|
#
|
||||||
|
# Modifies shell initialization files to bootstrap rbenv functionality.
|
||||||
|
# Typically, this will add a line that eval's the output of `rbenv init -`.
|
||||||
|
# If no shells are named by arguments, the current shell will be detected
|
||||||
|
# by inspecting the parent process. If a shell is already configured for
|
||||||
|
# rbenv, the init command does nothing and exits with zero status.
|
||||||
|
#
|
||||||
|
# In the `rbenv init -` mode, this outputs a script to be eval'd in the
|
||||||
|
# current shell. Most importantly, that script prepends the rbenv shims
|
||||||
|
# directory to the PATH environment variable. To aid interactive shells,
|
||||||
|
# the script also installs the magic `rbenv()` shell function and loads
|
||||||
|
# shell completions for rbenv commands.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
@@ -18,96 +31,148 @@ fi
|
|||||||
|
|
||||||
print=""
|
print=""
|
||||||
no_rehash=""
|
no_rehash=""
|
||||||
for args in "$@"
|
shells=()
|
||||||
do
|
while [ $# -gt 0 ]; do
|
||||||
if [ "$args" = "-" ]; then
|
case "$1" in
|
||||||
|
"-" )
|
||||||
print=1
|
print=1
|
||||||
shift
|
;;
|
||||||
fi
|
"--no-rehash" )
|
||||||
|
|
||||||
if [ "$args" = "--no-rehash" ]; then
|
|
||||||
no_rehash=1
|
no_rehash=1
|
||||||
shift
|
;;
|
||||||
fi
|
* )
|
||||||
|
shells+=("$1")
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
shell="$1"
|
if [ "${#shells[@]}" -eq 0 ]; then
|
||||||
if [ -z "$shell" ]; then
|
|
||||||
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
|
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
|
||||||
shell="${shell%% *}"
|
shell="${shell%% *}"
|
||||||
shell="${shell##-}"
|
shell="${shell##-}"
|
||||||
shell="${shell:-$SHELL}"
|
shell="${shell:-$SHELL}"
|
||||||
shell="${shell##*/}"
|
shell="${shell##*/}"
|
||||||
|
shells=("${shell%%-*}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
root="${0%/*}/.."
|
root="${BASH_SOURCE:-$0}"
|
||||||
|
root="${root%/*}"
|
||||||
|
root="${root%/*}"
|
||||||
|
|
||||||
|
rbenv_in_path=true
|
||||||
|
if [ -n "$RBENV_ORIG_PATH" ]; then
|
||||||
|
PATH="$RBENV_ORIG_PATH" type -P rbenv >/dev/null || rbenv_in_path=""
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$print" ]; then
|
if [ -z "$print" ]; then
|
||||||
case "$shell" in
|
display_path() {
|
||||||
bash )
|
if [ "${1/#$HOME\/}" != "$1" ]; then
|
||||||
if [ -f "${HOME}/.bashrc" ] && [ ! -f "${HOME}/.bash_profile" ]; then
|
# shellcheck disable=SC2088
|
||||||
profile='~/.bashrc'
|
printf '~/%s' "${1/#$HOME\/}"
|
||||||
else
|
else
|
||||||
profile='~/.bash_profile'
|
printf '%s' "$1"
|
||||||
fi
|
fi
|
||||||
;;
|
}
|
||||||
zsh )
|
|
||||||
profile='~/.zshrc'
|
|
||||||
;;
|
|
||||||
ksh )
|
|
||||||
profile='~/.profile'
|
|
||||||
;;
|
|
||||||
fish )
|
|
||||||
profile='~/.config/fish/config.fish'
|
|
||||||
;;
|
|
||||||
* )
|
|
||||||
profile='your profile'
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
{ echo "# Load rbenv automatically by appending"
|
rbenv_command=rbenv
|
||||||
echo "# the following to ${profile}:"
|
if [ -z "$rbenv_in_path" ]; then
|
||||||
echo
|
rbenv_command="$(display_path "$root/bin/rbenv")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
color_start=""
|
||||||
|
color_end=""
|
||||||
|
if [ -t 1 ]; then
|
||||||
|
color_start=$'\e[33;1m'
|
||||||
|
color_end=$'\e[m'
|
||||||
|
fi
|
||||||
|
|
||||||
|
write_config() {
|
||||||
|
if grep -q "rbenv init" "$1" 2>/dev/null; then
|
||||||
|
printf 'skipping %s%s%s: already configured for rbenv.\n' "$color_start" "$(display_path "$1")" "$color_end"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
mkdir -p "${1%/*}"
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
printf '\n# Added by `rbenv init` on %s\n%s\n' "$(date)" "$2" >> "$1"
|
||||||
|
printf 'writing %s%s%s: now configured for rbenv.\n' "$color_start" "$(display_path "$1")" "$color_end"
|
||||||
|
}
|
||||||
|
|
||||||
|
status=0
|
||||||
|
for shell in "${shells[@]}"; do
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
|
bash )
|
||||||
|
if [ -f ~/.bashrc ] && [ ! -f ~/.bash_profile ]; then
|
||||||
|
profile="$HOME/.bashrc"
|
||||||
|
else
|
||||||
|
# shellcheck disable=SC2012
|
||||||
|
profile="$(ls ~/.bash_profile ~/.bash_login ~/.profile 2>/dev/null | head -n1)"
|
||||||
|
[ -n "$profile" ] || profile="$HOME/.bash_profile"
|
||||||
|
fi
|
||||||
|
write_config "$profile" \
|
||||||
|
"eval \"\$($rbenv_command init - --no-rehash bash)\""
|
||||||
|
;;
|
||||||
|
zsh )
|
||||||
|
# check zshrc for backward compatibility with older rbenv init
|
||||||
|
if grep -q rbenv "${ZDOTDIR:-$HOME}/.zshrc" 2>/dev/null; then
|
||||||
|
profile="${ZDOTDIR:-$HOME}/.zshrc"
|
||||||
|
else
|
||||||
|
profile="${ZDOTDIR:-$HOME}/.zprofile"
|
||||||
|
fi
|
||||||
|
write_config "$profile" \
|
||||||
|
"eval \"\$($rbenv_command init - --no-rehash zsh)\""
|
||||||
|
;;
|
||||||
|
ksh | ksh93 | mksh )
|
||||||
|
# There are two implementations of Korn shell: AT&T (ksh93) and Mir (mksh).
|
||||||
|
# Systems may have them installed under those names, or as ksh, so those
|
||||||
|
# are recognized here. The obsolete ksh88 (subsumed by ksh93) and pdksh
|
||||||
|
# (subsumed by mksh) are not included, since they are unlikely to still
|
||||||
|
# be in use as interactive shells anywhere.
|
||||||
|
write_config "$HOME/.profile" \
|
||||||
|
"eval \"\$($rbenv_command init - ksh)\""
|
||||||
|
;;
|
||||||
fish )
|
fish )
|
||||||
echo 'status --is-interactive; and . (rbenv init -|psub)'
|
write_config "${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish" \
|
||||||
|
"status --is-interactive; and $rbenv_command init - --no-rehash fish | source"
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
echo 'eval "$(rbenv init -)"'
|
printf 'unsupported shell: "%s"\n' "$shell" >&2
|
||||||
|
status=1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
echo
|
done
|
||||||
} >&2
|
exit $status
|
||||||
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "${RBENV_ROOT}/"{shims,versions}
|
mkdir -p "${RBENV_ROOT}/"{shims,versions}
|
||||||
|
|
||||||
|
shell="${shells[0]}"
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
fish )
|
fish )
|
||||||
echo "setenv PATH '${RBENV_ROOT}/shims' \$PATH"
|
[ -n "$rbenv_in_path" ] || printf "set -gx PATH '%s/bin' \$PATH\n" "$root"
|
||||||
echo "setenv RBENV_SHELL $shell"
|
printf "set -gx PATH '%s/shims' \$PATH\n" "$RBENV_ROOT"
|
||||||
|
printf 'set -gx RBENV_SHELL %s\n' "$shell"
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
|
# shellcheck disable=SC2016
|
||||||
echo "export RBENV_SHELL=$shell"
|
[ -n "$rbenv_in_path" ] || printf 'export PATH="%s/bin:${PATH}"\n' "$root"
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
printf 'export PATH="%s/shims:${PATH}"\n' "$RBENV_ROOT"
|
||||||
|
printf 'export RBENV_SHELL=%s\n' "$shell"
|
||||||
|
|
||||||
|
completion="${root}/completions/rbenv.${shell}"
|
||||||
|
if [ -r "$completion" ]; then
|
||||||
|
printf "source '%s'\n" "$completion"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
completion="${root}/completions/rbenv.${shell}"
|
|
||||||
if [ -r "$completion" ]; then
|
|
||||||
case "$shell" in
|
|
||||||
fish ) echo ". '$completion'" ;;
|
|
||||||
* ) echo "source '$completion'" ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$no_rehash" ]; then
|
if [ -z "$no_rehash" ]; then
|
||||||
echo 'command rbenv rehash 2>/dev/null'
|
echo 'command rbenv rehash 2>/dev/null'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
commands=(`rbenv-commands --sh`)
|
IFS=$'\n' read -d '' -r -a commands <<<"$(rbenv-commands --sh)" || true
|
||||||
|
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
fish )
|
fish )
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
@@ -117,14 +182,14 @@ function rbenv
|
|||||||
|
|
||||||
switch "\$command"
|
switch "\$command"
|
||||||
case ${commands[*]}
|
case ${commands[*]}
|
||||||
. (rbenv "sh-\$command" \$argv|psub)
|
rbenv "sh-\$command" \$argv|source
|
||||||
case '*'
|
case '*'
|
||||||
command rbenv "\$command" \$argv
|
command rbenv "\$command" \$argv
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
EOS
|
EOS
|
||||||
;;
|
;;
|
||||||
ksh )
|
ksh | ksh93 | mksh )
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
function rbenv {
|
function rbenv {
|
||||||
typeset command
|
typeset command
|
||||||
@@ -141,7 +206,7 @@ esac
|
|||||||
if [ "$shell" != "fish" ]; then
|
if [ "$shell" != "fish" ]; then
|
||||||
IFS="|"
|
IFS="|"
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
command="\$1"
|
command="\${1:-}"
|
||||||
if [ "\$#" -gt 0 ]; then
|
if [ "\$#" -gt 0 ]; then
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ elif [ -z "$RBENV_VERSION" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$RBENV_VERSION" = "system" ]; then
|
if [ "$RBENV_VERSION" = "system" ]; then
|
||||||
if RUBY_PATH="$(rbenv-which ruby 2>/dev/null)"; then
|
if RUBY_PATH="$(rbenv-which ruby)"; then
|
||||||
RUBY_PATH="${RUBY_PATH%/*}"
|
RUBY_PATH="${RUBY_PATH%/*}"
|
||||||
echo "${RUBY_PATH%/bin}"
|
RBENV_PREFIX_PATH="${RUBY_PATH%/bin}"
|
||||||
|
echo "${RBENV_PREFIX_PATH:-/}"
|
||||||
exit
|
exit
|
||||||
else
|
else
|
||||||
echo "rbenv: system version not found in PATH" >&2
|
echo "rbenv: system version not found in PATH" >&2
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Summary: Rehash rbenv shims (run this after installing executables)
|
# Summary: Regenerate rbenv shims
|
||||||
|
#
|
||||||
|
# Regenerate shims for every Ruby executable in `$RBENV_ROOT/versions/*/bin'
|
||||||
|
# and write them to the `$RBENV_ROOT/shims' directory. A shell environment
|
||||||
|
# properly set up for rbenv will have this shims directory in PATH, which is
|
||||||
|
# the core mechanism for Ruby version switching.
|
||||||
|
#
|
||||||
|
# Running rbenv rehash should only be necessary after installing new Ruby
|
||||||
|
# versions or gems. Note that this is sometimes done automatically: the
|
||||||
|
# `rbenv install' command from the ruby-build plugin runs rehash after
|
||||||
|
# every successful installation, and a RubyGems plugin that ships with
|
||||||
|
# rbenv runs rehash after every `gem install' command.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
@@ -16,7 +27,7 @@ mkdir -p "$SHIM_PATH"
|
|||||||
# to stderr and exit with a non-zero status.
|
# to stderr and exit with a non-zero status.
|
||||||
set -o noclobber
|
set -o noclobber
|
||||||
{ echo > "$PROTOTYPE_SHIM_PATH"
|
{ echo > "$PROTOTYPE_SHIM_PATH"
|
||||||
} 2>/dev/null ||
|
} 2>| /dev/null ||
|
||||||
{ if [ -w "$SHIM_PATH" ]; then
|
{ if [ -w "$SHIM_PATH" ]; then
|
||||||
echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
|
echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
|
||||||
else
|
else
|
||||||
@@ -34,6 +45,21 @@ remove_prototype_shim() {
|
|||||||
rm -f "$PROTOTYPE_SHIM_PATH"
|
rm -f "$PROTOTYPE_SHIM_PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Locates rbenv as found in the user's PATH. Otherwise, returns an
|
||||||
|
# absolute path to the rbenv executable itself.
|
||||||
|
rbenv_path() {
|
||||||
|
local found
|
||||||
|
found="$(PATH="$RBENV_ORIG_PATH" type -P rbenv)"
|
||||||
|
if [[ $found == /* ]]; then
|
||||||
|
echo "$found"
|
||||||
|
elif [[ -n "$found" ]]; then
|
||||||
|
echo "$PWD/${found#./}"
|
||||||
|
else
|
||||||
|
# Assume rbenv isn't in PATH.
|
||||||
|
echo "${BASH_SOURCE%/*}/rbenv"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# The prototype shim file is a script that re-execs itself, passing
|
# The prototype shim file is a script that re-execs itself, passing
|
||||||
# its filename and any arguments to `rbenv exec`. This file is
|
# its filename and any arguments to `rbenv exec`. This file is
|
||||||
# hard-linked for every executable and then removed. The linking
|
# hard-linked for every executable and then removed. The linking
|
||||||
@@ -61,7 +87,7 @@ if [ "\$program" = "ruby" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
export RBENV_ROOT="$RBENV_ROOT"
|
export RBENV_ROOT="$RBENV_ROOT"
|
||||||
exec "$(command -v rbenv)" exec "\$program" "\$@"
|
exec "$(rbenv_path)" exec "\$program" "\$@"
|
||||||
SH
|
SH
|
||||||
chmod +x "$PROTOTYPE_SHIM_PATH"
|
chmod +x "$PROTOTYPE_SHIM_PATH"
|
||||||
}
|
}
|
||||||
@@ -83,11 +109,16 @@ remove_outdated_shims() {
|
|||||||
list_executable_names() {
|
list_executable_names() {
|
||||||
local version file
|
local version file
|
||||||
rbenv-versions --bare --skip-aliases | \
|
rbenv-versions --bare --skip-aliases | \
|
||||||
while read version; do
|
while read -r version; do
|
||||||
for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do
|
for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do
|
||||||
echo "${file##*/}"
|
echo "${file##*/}"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
if [ -n "$GEM_HOME" ]; then
|
||||||
|
for file in "$GEM_HOME"/bin/*; do
|
||||||
|
echo "${file##*/}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# The basename of each argument passed to `make_shims` will be
|
# The basename of each argument passed to `make_shims` will be
|
||||||
@@ -97,21 +128,19 @@ make_shims() {
|
|||||||
local file shim
|
local file shim
|
||||||
for file; do
|
for file; do
|
||||||
shim="${file##*/}"
|
shim="${file##*/}"
|
||||||
register_shim "$shim"
|
registered_shims+=("$shim")
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
registered_shims=" "
|
|
||||||
|
|
||||||
# Registers the name of a shim to be generated.
|
# Registers the name of a shim to be generated.
|
||||||
register_shim() {
|
register_shim() {
|
||||||
registered_shims="${registered_shims}${1} "
|
registered_shims+=("$1")
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install all the shims registered via `make_shims` or `register_shim` directly.
|
# Install all the shims registered via `make_shims` or `register_shim` directly.
|
||||||
install_registered_shims() {
|
install_registered_shims() {
|
||||||
local shim file
|
local shim file
|
||||||
for shim in $registered_shims; do
|
for shim in "${registered_shims[@]}"; do
|
||||||
file="${SHIM_PATH}/${shim}"
|
file="${SHIM_PATH}/${shim}"
|
||||||
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
|
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
|
||||||
done
|
done
|
||||||
@@ -123,8 +152,9 @@ install_registered_shims() {
|
|||||||
# removed.
|
# removed.
|
||||||
remove_stale_shims() {
|
remove_stale_shims() {
|
||||||
local shim
|
local shim
|
||||||
|
local known_shims=" ${registered_shims[*]} "
|
||||||
for shim in "$SHIM_PATH"/*; do
|
for shim in "$SHIM_PATH"/*; do
|
||||||
if [[ "$registered_shims" != *" ${shim##*/} "* ]]; then
|
if [[ "$known_shims" != *" ${shim##*/} "* ]]; then
|
||||||
rm -f "$shim"
|
rm -f "$shim"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -136,15 +166,13 @@ shopt -s nullglob
|
|||||||
# executables.
|
# executables.
|
||||||
create_prototype_shim
|
create_prototype_shim
|
||||||
remove_outdated_shims
|
remove_outdated_shims
|
||||||
make_shims $(list_executable_names | sort -u)
|
# shellcheck disable=SC2207
|
||||||
|
registered_shims=( $(list_executable_names | sort -u) )
|
||||||
|
|
||||||
# Allow plugins to register shims.
|
# Allow plugins to register shims.
|
||||||
OLDIFS="$IFS"
|
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks rehash)" || true
|
||||||
IFS=$'\n' scripts=(`rbenv-hooks rehash`)
|
|
||||||
IFS="$OLDIFS"
|
|
||||||
|
|
||||||
for script in "${scripts[@]}"; do
|
for script in "${scripts[@]}"; do
|
||||||
|
# shellcheck disable=SC1090
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Summary: Display the root directory where versions and shims are kept
|
# Summary: Display the root directory where versions and shims are kept
|
||||||
echo $RBENV_ROOT
|
echo "$RBENV_ROOT"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
# Summary: Set or show the shell-specific Ruby version
|
# Summary: Set or show the shell-specific Ruby version
|
||||||
#
|
#
|
||||||
# Usage: rbenv shell <version>
|
# Usage: rbenv shell <version>
|
||||||
|
# rbenv shell -
|
||||||
# rbenv shell --unset
|
# rbenv shell --unset
|
||||||
#
|
#
|
||||||
# Sets a shell-specific Ruby version by setting the `RBENV_VERSION'
|
# Sets a shell-specific Ruby version by setting the `RBENV_VERSION'
|
||||||
@@ -12,6 +13,11 @@
|
|||||||
# <version> should be a string matching a Ruby version known to rbenv.
|
# <version> should be a string matching a Ruby version known to rbenv.
|
||||||
# The special version string `system' will use your default system Ruby.
|
# The special version string `system' will use your default system Ruby.
|
||||||
# Run `rbenv versions' for a list of available Ruby versions.
|
# Run `rbenv versions' for a list of available Ruby versions.
|
||||||
|
#
|
||||||
|
# When `-` is passed instead of the version string, the previously set
|
||||||
|
# version will be restored. With `--unset`, the `RBENV_VERSION`
|
||||||
|
# environment variable gets unset, restoring the environment to the
|
||||||
|
# state before the first `rbenv shell` call.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
@@ -31,7 +37,7 @@ if [ -z "$version" ]; then
|
|||||||
echo "rbenv: no shell-specific version configured" >&2
|
echo "rbenv: no shell-specific version configured" >&2
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "echo \"\$RBENV_VERSION\""
|
echo 'echo "$RBENV_VERSION"'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -39,25 +45,99 @@ fi
|
|||||||
if [ "$version" = "--unset" ]; then
|
if [ "$version" = "--unset" ]; then
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
fish )
|
fish )
|
||||||
|
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
||||||
echo "set -e RBENV_VERSION"
|
echo "set -e RBENV_VERSION"
|
||||||
;;
|
;;
|
||||||
* )
|
zsh )
|
||||||
|
echo "typeset -g RBENV_VERSION_OLD=\"\${RBENV_VERSION-}\""
|
||||||
echo "unset RBENV_VERSION"
|
echo "unset RBENV_VERSION"
|
||||||
;;
|
;;
|
||||||
|
* )
|
||||||
|
echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
|
||||||
|
echo "unset RBENV_VERSION"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$version" = "-" ]; then
|
||||||
|
case "$shell" in
|
||||||
|
fish )
|
||||||
|
cat <<EOS
|
||||||
|
if set -q RBENV_VERSION_OLD
|
||||||
|
if [ -n "\$RBENV_VERSION_OLD" ]
|
||||||
|
set RBENV_VERSION_OLD_ "\$RBENV_VERSION"
|
||||||
|
set -gx RBENV_VERSION "\$RBENV_VERSION_OLD"
|
||||||
|
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION_OLD_"
|
||||||
|
set -e RBENV_VERSION_OLD_
|
||||||
|
else
|
||||||
|
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
||||||
|
set -e RBENV_VERSION
|
||||||
|
end
|
||||||
|
else
|
||||||
|
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||||
|
false
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
;;
|
||||||
|
zsh )
|
||||||
|
cat <<EOS
|
||||||
|
if [ -n "\${RBENV_VERSION_OLD+x}" ]; then
|
||||||
|
if [ -n "\$RBENV_VERSION_OLD" ]; then
|
||||||
|
local RBENV_VERSION_OLD_="\$RBENV_VERSION"
|
||||||
|
export RBENV_VERSION="\$RBENV_VERSION_OLD"
|
||||||
|
RBENV_VERSION_OLD="\$RBENV_VERSION_OLD_"
|
||||||
|
unset RBENV_VERSION_OLD_
|
||||||
|
else
|
||||||
|
typeset -g RBENV_VERSION_OLD="\$RBENV_VERSION"
|
||||||
|
unset RBENV_VERSION
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
EOS
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
cat <<EOS
|
||||||
|
if [ -n "\${RBENV_VERSION_OLD+x}" ]; then
|
||||||
|
if [ -n "\$RBENV_VERSION_OLD" ]; then
|
||||||
|
RBENV_VERSION_OLD_="\$RBENV_VERSION"
|
||||||
|
export RBENV_VERSION="\$RBENV_VERSION_OLD"
|
||||||
|
RBENV_VERSION_OLD="\$RBENV_VERSION_OLD_"
|
||||||
|
unset RBENV_VERSION_OLD_
|
||||||
|
else
|
||||||
|
RBENV_VERSION_OLD="\$RBENV_VERSION"
|
||||||
|
unset RBENV_VERSION
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
EOS
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make sure the specified version is installed.
|
# Make sure the specified version is installed.
|
||||||
if rbenv-prefix "$version" >/dev/null; then
|
if rbenv-prefix "$version" >/dev/null; then
|
||||||
case "$shell" in
|
if [ "$version" != "$RBENV_VERSION" ]; then
|
||||||
fish )
|
case "$shell" in
|
||||||
echo "setenv RBENV_VERSION \"${version}\""
|
fish )
|
||||||
;;
|
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
||||||
* )
|
echo "set -gx RBENV_VERSION \"$version\""
|
||||||
echo "export RBENV_VERSION=\"${version}\""
|
;;
|
||||||
;;
|
zsh )
|
||||||
esac
|
echo "typeset -g RBENV_VERSION_OLD=\"\${RBENV_VERSION-}\""
|
||||||
|
echo "export RBENV_VERSION=\"$version\""
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
|
||||||
|
echo "export RBENV_VERSION=\"$version\""
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "false"
|
echo "false"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -8,4 +8,11 @@
|
|||||||
set -e
|
set -e
|
||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
echo "$(rbenv-version-name) (set by $(rbenv-version-origin))"
|
version_name="$(rbenv-version-name)"
|
||||||
|
version_origin="$(rbenv-version-origin)"
|
||||||
|
|
||||||
|
if [ "$version_origin" = "${RBENV_ROOT}/version" ] && [ ! -e "$version_origin" ]; then
|
||||||
|
echo "$version_name"
|
||||||
|
else
|
||||||
|
echo "$version_name (set by $version_origin)"
|
||||||
|
fi
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Usage: rbenv version-file [<dir>]
|
# Usage: rbenv version-file [<dir>]
|
||||||
# Summary: Detect the file that sets the current rbenv version
|
# Summary: Detect the file that sets the current rbenv version
|
||||||
|
#
|
||||||
|
# Detects and prints the location of a `.ruby-version` file that sets the
|
||||||
|
# version for the current working directory. If no file found, this prints
|
||||||
|
# the location of the global version file, even if that file does
|
||||||
|
# not exist.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
@@ -9,7 +15,7 @@ target_dir="$1"
|
|||||||
find_local_version_file() {
|
find_local_version_file() {
|
||||||
local root="$1"
|
local root="$1"
|
||||||
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
|
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
|
||||||
if [ -e "${root}/.ruby-version" ]; then
|
if [ -s "${root}/.ruby-version" ]; then
|
||||||
echo "${root}/.ruby-version"
|
echo "${root}/.ruby-version"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ set -e
|
|||||||
|
|
||||||
VERSION_FILE="$1"
|
VERSION_FILE="$1"
|
||||||
|
|
||||||
if [ -e "$VERSION_FILE" ]; then
|
if [ -s "$VERSION_FILE" ]; then
|
||||||
# Read the first non-whitespace word from the specified version file.
|
# Read the first word from the specified version file. Avoid reading it whole.
|
||||||
# Be careful not to load it whole in case there's something crazy in it.
|
|
||||||
IFS="${IFS}"$'\r'
|
IFS="${IFS}"$'\r'
|
||||||
words=( $(cut -b 1-1024 "$VERSION_FILE") )
|
read -n 1024 -d "" -r version _ <"$VERSION_FILE" || :
|
||||||
version="${words[0]}"
|
|
||||||
|
|
||||||
if [ -n "$version" ]; then
|
if [ "$version" = ".." ] || [[ $version == */* ]]; then
|
||||||
|
echo "rbenv: invalid version in \`$VERSION_FILE'" >&2
|
||||||
|
elif [ -n "$version" ]; then
|
||||||
echo "$version"
|
echo "$version"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ if [ -z "$RBENV_VERSION" ]; then
|
|||||||
RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)"
|
RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OLDIFS="$IFS"
|
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-name)" || true
|
||||||
IFS=$'\n' scripts=(`rbenv-hooks version-name`)
|
|
||||||
IFS="$OLDIFS"
|
|
||||||
for script in "${scripts[@]}"; do
|
for script in "${scripts[@]}"; do
|
||||||
|
# shellcheck disable=SC1090
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ set -e
|
|||||||
|
|
||||||
unset RBENV_VERSION_ORIGIN
|
unset RBENV_VERSION_ORIGIN
|
||||||
|
|
||||||
OLDIFS="$IFS"
|
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-origin)" || true
|
||||||
IFS=$'\n' scripts=(`rbenv-hooks version-origin`)
|
|
||||||
IFS="$OLDIFS"
|
|
||||||
for script in "${scripts[@]}"; do
|
for script in "${scripts[@]}"; do
|
||||||
|
# shellcheck disable=SC1090
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Summary: List all Ruby versions available to rbenv
|
# Summary: List installed Ruby versions
|
||||||
# Usage: rbenv versions [--bare] [--skip-aliases]
|
# Usage: rbenv versions [--bare] [--skip-aliases]
|
||||||
#
|
#
|
||||||
# Lists all Ruby versions found in `$RBENV_ROOT/versions/*'.
|
# Lists all Ruby versions found in `$RBENV_ROOT/versions/*'.
|
||||||
@@ -25,85 +25,59 @@ for arg; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
versions_dir="${RBENV_ROOT}/versions"
|
canonicalize_dir() {
|
||||||
|
{ cd "$1" && pwd -P
|
||||||
if ! enable -f "${BASH_SOURCE%/*}"/rbenv-realpath.dylib realpath 2>/dev/null; then
|
} 2>/dev/null || echo "$1"
|
||||||
if [ -n "$RBENV_NATIVE_EXT" ]; then
|
|
||||||
echo "rbenv: failed to load \`realpath' builtin" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
READLINK=$(type -p greadlink readlink | head -1)
|
|
||||||
if [ -z "$READLINK" ]; then
|
|
||||||
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
resolve_link() {
|
|
||||||
$READLINK "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
realpath() {
|
|
||||||
local cwd="$PWD"
|
|
||||||
local path="$1"
|
|
||||||
local name
|
|
||||||
|
|
||||||
while [ -n "$path" ]; do
|
|
||||||
name="${path##*/}"
|
|
||||||
[ "$name" = "$path" ] || cd "${path%/*}"
|
|
||||||
path="$(resolve_link "$name" || true)"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "${PWD}/$name"
|
|
||||||
cd "$cwd"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -d "$versions_dir" ]; then
|
|
||||||
versions_dir="$(realpath "$versions_dir")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$bare" ]; then
|
|
||||||
hit_prefix=""
|
|
||||||
miss_prefix=""
|
|
||||||
current_version=""
|
|
||||||
include_system=""
|
|
||||||
else
|
|
||||||
hit_prefix="* "
|
|
||||||
miss_prefix=" "
|
|
||||||
current_version="$(rbenv-version-name || true)"
|
|
||||||
include_system="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
num_versions=0
|
|
||||||
|
|
||||||
print_version() {
|
|
||||||
if [ "$1" == "$current_version" ]; then
|
|
||||||
echo "${hit_prefix}$(rbenv-version 2>/dev/null)"
|
|
||||||
else
|
|
||||||
echo "${miss_prefix}$1"
|
|
||||||
fi
|
|
||||||
num_versions=$((num_versions + 1))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Include "system" in the non-bare output, if it exists
|
versions_dir="${RBENV_ROOT}/versions"
|
||||||
if [ -n "$include_system" ] && RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then
|
if [ -n "$skip_aliases" ]; then
|
||||||
print_version system
|
versions_dir="$(canonicalize_dir "$versions_dir")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shopt -s nullglob
|
list_versions() {
|
||||||
for path in "$versions_dir"/*; do
|
local path
|
||||||
if [ -d "$path" ]; then
|
local target
|
||||||
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
|
shopt -s nullglob
|
||||||
target="$(realpath "$path")"
|
for path in "$versions_dir"/*; do
|
||||||
[ "${target%/*}" != "$versions_dir" ] || continue
|
if [ -d "$path" ]; then
|
||||||
|
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
|
||||||
|
target="$(canonicalize_dir "$path")"
|
||||||
|
[ "${target%/*}" != "$versions_dir" ] || continue
|
||||||
|
fi
|
||||||
|
echo "${path##*/}"
|
||||||
fi
|
fi
|
||||||
print_version "${path##*/}"
|
done
|
||||||
fi
|
shopt -u nullglob
|
||||||
done
|
}
|
||||||
shopt -u nullglob
|
|
||||||
|
|
||||||
if [ "$num_versions" -eq 0 ] && [ -n "$include_system" ]; then
|
if [ -n "$bare" ]; then
|
||||||
|
list_versions
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
sort_versions() {
|
||||||
|
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /' | \
|
||||||
|
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
|
||||||
|
}
|
||||||
|
|
||||||
|
versions="$(
|
||||||
|
if RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then
|
||||||
|
echo system
|
||||||
|
fi
|
||||||
|
list_versions | sort_versions
|
||||||
|
)"
|
||||||
|
|
||||||
|
if [ -z "$versions" ]; then
|
||||||
echo "Warning: no Ruby detected on the system" >&2
|
echo "Warning: no Ruby detected on the system" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
current_version="$(rbenv-version-name || true)"
|
||||||
|
while read -r version; do
|
||||||
|
if [ "$version" == "$current_version" ]; then
|
||||||
|
echo "* $(rbenv-version 2>/dev/null)"
|
||||||
|
else
|
||||||
|
echo " $version"
|
||||||
|
fi
|
||||||
|
done <<<"$versions"
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ fi
|
|||||||
|
|
||||||
whence() {
|
whence() {
|
||||||
local command="$1"
|
local command="$1"
|
||||||
rbenv-versions --bare | while read version; do
|
rbenv-versions --bare | while read -r version; do
|
||||||
path="$(rbenv-prefix "$version")/bin/${command}"
|
path="$(rbenv-prefix "$version")/bin/${command}"
|
||||||
if [ -x "$path" ]; then
|
if [ -x "$path" ]; then
|
||||||
[ "$print_paths" ] && echo "$path" || echo "$version"
|
[ "$print_paths" ] && echo "$path" || echo "$version"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ fi
|
|||||||
remove_from_path() {
|
remove_from_path() {
|
||||||
local path_to_remove="$1"
|
local path_to_remove="$1"
|
||||||
local path_before
|
local path_before
|
||||||
local result=":$PATH:"
|
local result=":${PATH//\~/$HOME}:"
|
||||||
while [ "$path_before" != "$result" ]; do
|
while [ "$path_before" != "$result" ]; do
|
||||||
path_before="$result"
|
path_before="$result"
|
||||||
result="${result//:$path_to_remove:/:}"
|
result="${result//:$path_to_remove:/:}"
|
||||||
@@ -37,16 +37,19 @@ fi
|
|||||||
RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}"
|
RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}"
|
||||||
|
|
||||||
if [ "$RBENV_VERSION" = "system" ]; then
|
if [ "$RBENV_VERSION" = "system" ]; then
|
||||||
PATH="$(remove_from_path "${RBENV_ROOT}/shims")"
|
PATH="$(remove_from_path "${RBENV_ROOT}/shims")" \
|
||||||
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)"
|
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)"
|
||||||
else
|
else
|
||||||
RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}"
|
RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OLDIFS="$IFS"
|
if [[ ! -x "$RBENV_COMMAND_PATH" && -n "$GEM_HOME" && -x "${GEM_HOME}/bin/${RBENV_COMMAND}" ]]; then
|
||||||
IFS=$'\n' scripts=(`rbenv-hooks which`)
|
RBENV_COMMAND_PATH="${GEM_HOME}/bin/${RBENV_COMMAND}"
|
||||||
IFS="$OLDIFS"
|
fi
|
||||||
|
|
||||||
|
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks which)" || true
|
||||||
for script in "${scripts[@]}"; do
|
for script in "${scripts[@]}"; do
|
||||||
|
# shellcheck disable=SC1090
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -10,27 +10,29 @@ hook = lambda do |installer|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) && !Bundler::Installer.respond_to?(:install_without_rbenv_rehash)
|
if defined?(Bundler::Installer) &&
|
||||||
|
Bundler::Installer.private_method_defined?(:install) &&
|
||||||
|
!Bundler::Installer.private_method_defined?(:install_without_rbenv_rehash)
|
||||||
Bundler::Installer.class_eval do
|
Bundler::Installer.class_eval do
|
||||||
class << self
|
private
|
||||||
alias install_without_rbenv_rehash install
|
|
||||||
def install(root, definition, options = {})
|
|
||||||
begin
|
|
||||||
if Gem.default_path.include?(Bundler.bundle_path.to_s)
|
|
||||||
bin_dir = Gem.bindir(Bundler.bundle_path.to_s)
|
|
||||||
bins_before = File.exist?(bin_dir) ? Dir.entries(bin_dir).size : 2
|
|
||||||
end
|
|
||||||
rescue
|
|
||||||
warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})"
|
|
||||||
end
|
|
||||||
|
|
||||||
result = install_without_rbenv_rehash(root, definition, options)
|
alias install_without_rbenv_rehash install
|
||||||
|
def install(options)
|
||||||
if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before
|
begin
|
||||||
`rbenv rehash`
|
if Gem.default_path.include?(Bundler.bundle_path.to_s)
|
||||||
|
bin_dir = Gem.bindir(Bundler.bundle_path.to_s)
|
||||||
|
bins_before = File.exist?(bin_dir) ? Dir.entries(bin_dir).size : 2
|
||||||
end
|
end
|
||||||
result
|
rescue
|
||||||
|
warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
result = install_without_rbenv_rehash(options)
|
||||||
|
|
||||||
|
if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before
|
||||||
|
`rbenv rehash`
|
||||||
|
end
|
||||||
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
163
share/man/man1/rbenv.1
generated
Normal file
163
share/man/man1/rbenv.1
generated
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
'\" t
|
||||||
|
.\" Title: rbenv
|
||||||
|
.\" Author: Mislav Marohnić
|
||||||
|
.\" Generator: Asciidoctor 2.0.20
|
||||||
|
.\" Date: 2023-11-08
|
||||||
|
.\" Manual: Rbenv Manual
|
||||||
|
.\" Source: rbenv 1.3.0
|
||||||
|
.\" Language: English
|
||||||
|
.\"
|
||||||
|
.TH "RBENV" "1" "2023-11-08" "rbenv 1.3.0" "Rbenv Manual"
|
||||||
|
.ie \n(.g .ds Aq \(aq
|
||||||
|
.el .ds Aq '
|
||||||
|
.ss \n[.ss] 0
|
||||||
|
.nh
|
||||||
|
.ad l
|
||||||
|
.de URL
|
||||||
|
\fI\\$2\fP <\\$1>\\$3
|
||||||
|
..
|
||||||
|
.als MTO URL
|
||||||
|
.if \n[.g] \{\
|
||||||
|
. mso www.tmac
|
||||||
|
. am URL
|
||||||
|
. ad l
|
||||||
|
. .
|
||||||
|
. am MTO
|
||||||
|
. ad l
|
||||||
|
. .
|
||||||
|
. LINKSTYLE blue R < >
|
||||||
|
.\}
|
||||||
|
.SH "NAME"
|
||||||
|
rbenv \- manage your application\*(Aqs Ruby environment
|
||||||
|
.SH "SYNOPSIS"
|
||||||
|
.sp
|
||||||
|
\fBrbenv\fP \fI<command>\fP [\fI<args>\fP...]
|
||||||
|
.SH "DESCRIPTION"
|
||||||
|
.sp
|
||||||
|
rbenv respects the \fI.ruby\-version\fP file in a project directory by making sure that any \fBruby\fP, \fBgem\fP, \fBbundle\fP, or other Ruby command invocation automatically invokes the Ruby version configured for that project.
|
||||||
|
.sp
|
||||||
|
It does so by generating shims for all Ruby executables. As long as rbenv shims directory is prepended to PATH, rbenv automatically ensures transparent switching between Ruby versions.
|
||||||
|
.sp
|
||||||
|
rbenv looks for available Ruby versions in the \fI$RBENV_ROOT/versions\fP directory.
|
||||||
|
.SH "COMMANDS"
|
||||||
|
.sp
|
||||||
|
\fBrbenv global\fP [\fI<version>\fP]
|
||||||
|
.RS 4
|
||||||
|
View or change the global Ruby version
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBrbenv local\fP [\fI<version>\fP]
|
||||||
|
.RS 4
|
||||||
|
View or change the local Ruby version
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBrbenv shell\fP [\fI<version>\fP]
|
||||||
|
.RS 4
|
||||||
|
View or change the Ruby version for the current shell session
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBrbenv version\fP
|
||||||
|
.RS 4
|
||||||
|
View the currently active Ruby version and where it is set from
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBrbenv versions\fP
|
||||||
|
.RS 4
|
||||||
|
List all locally installed Ruby versions known to rbenv
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBrbenv install\fP [\fI<version>\fP]
|
||||||
|
.RS 4
|
||||||
|
(Provided by the \fBruby\-build\fP plugin) Download and install a new Ruby version
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBrbenv rehash\fP
|
||||||
|
.RS 4
|
||||||
|
Regenerate shims for all known Ruby executables
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBrbenv which\fP [\fI<command>\fP]
|
||||||
|
.RS 4
|
||||||
|
View the executable path that a command resolves to
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBrbenv init\fP
|
||||||
|
.RS 4
|
||||||
|
Help bootstrap rbenv into the current shell environment
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBrbenv help\fP [\fI<command>\fP]
|
||||||
|
.RS 4
|
||||||
|
View help text for any rbenv command
|
||||||
|
.RE
|
||||||
|
.SH "ENVIRONMENT VARIABLES"
|
||||||
|
.sp
|
||||||
|
\fBRBENV_VERSION\fP (default: read from \fI.ruby\-version\fP file)
|
||||||
|
.RS 4
|
||||||
|
The Ruby version name to be used
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBRBENV_ROOT\fP (default: \fI~/.rbenv\fP)
|
||||||
|
.RS 4
|
||||||
|
The location where rbenv discovers Ruby versions, plugins, and other configuration
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBRBENV_DEBUG\fP
|
||||||
|
.RS 4
|
||||||
|
Activates printing debug information about rbenv internals to standard error
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBRBENV_HOOK_PATH\fP
|
||||||
|
.RS 4
|
||||||
|
Colon\-separated list of paths searched for rbenv plugin scripts
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
\fBRBENV_DIR\fP (default: \fI$PWD\fP)
|
||||||
|
.RS 4
|
||||||
|
Directory to traverse bottom\-up to locate the \fI.ruby\-version\fP file
|
||||||
|
.RE
|
||||||
|
.SH "PLUGINS"
|
||||||
|
.sp
|
||||||
|
As its core functionality, rbenv only switches between Ruby versions and does nothing else, but offers a plugin mechanism to hook into and override almost any aspect of its default behavior.
|
||||||
|
.sp
|
||||||
|
The most common plugin for rbenv is \fBruby\-build\fP which facilitates installing new Ruby versions into the \fI$RBENV_ROOT/versions\fP directory.
|
||||||
|
.sp
|
||||||
|
Read more at \c
|
||||||
|
.URL "https://github.com/rbenv/rbenv/wiki/Plugins" "" ""
|
||||||
|
.SH "NOTES"
|
||||||
|
.sp
|
||||||
|
.RS 4
|
||||||
|
.ie n \{\
|
||||||
|
\h'-04'\(bu\h'+03'\c
|
||||||
|
.\}
|
||||||
|
.el \{\
|
||||||
|
. sp -1
|
||||||
|
. IP \(bu 2.3
|
||||||
|
.\}
|
||||||
|
.URL "https://github.com/rbenv/rbenv/discussions" "" ""
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
.RS 4
|
||||||
|
.ie n \{\
|
||||||
|
\h'-04'\(bu\h'+03'\c
|
||||||
|
.\}
|
||||||
|
.el \{\
|
||||||
|
. sp -1
|
||||||
|
. IP \(bu 2.3
|
||||||
|
.\}
|
||||||
|
.URL "https://github.com/rbenv/rbenv/wiki" "" ""
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
.RS 4
|
||||||
|
.ie n \{\
|
||||||
|
\h'-04'\(bu\h'+03'\c
|
||||||
|
.\}
|
||||||
|
.el \{\
|
||||||
|
. sp -1
|
||||||
|
. IP \(bu 2.3
|
||||||
|
.\}
|
||||||
|
.URL "https://github.com/rbenv/ruby\-build#readme" "" ""
|
||||||
|
.RE
|
||||||
|
.SH "AUTHOR"
|
||||||
|
.sp
|
||||||
|
Mislav Marohnić
|
||||||
87
share/man/man1/rbenv.1.adoc
Normal file
87
share/man/man1/rbenv.1.adoc
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
= rbenv(1)
|
||||||
|
Mislav Marohnić
|
||||||
|
:doctype: manpage
|
||||||
|
:man manual: Rbenv Manual
|
||||||
|
:man source: rbenv {version}
|
||||||
|
:man-linkstyle: pass:[blue R < >]
|
||||||
|
|
||||||
|
== Name
|
||||||
|
|
||||||
|
rbenv - manage your application's Ruby environment
|
||||||
|
|
||||||
|
== Synopsis
|
||||||
|
|
||||||
|
*rbenv* _<command>_ [_<args>_...]
|
||||||
|
|
||||||
|
== Description
|
||||||
|
|
||||||
|
rbenv respects the _.ruby-version_ file in a project directory by making sure that any *ruby*, *gem*, *bundle*, or other Ruby command invocation automatically invokes the Ruby version configured for that project.
|
||||||
|
|
||||||
|
It does so by generating shims for all Ruby executables. As long as rbenv shims directory is prepended to PATH, rbenv automatically ensures transparent switching between Ruby versions.
|
||||||
|
|
||||||
|
rbenv looks for available Ruby versions in the _$RBENV_ROOT/versions_ directory.
|
||||||
|
|
||||||
|
== Commands
|
||||||
|
|
||||||
|
*rbenv global* [_<version>_]::
|
||||||
|
View or change the global Ruby version
|
||||||
|
|
||||||
|
*rbenv local* [_<version>_]::
|
||||||
|
View or change the local Ruby version
|
||||||
|
|
||||||
|
*rbenv shell* [_<version>_]::
|
||||||
|
View or change the Ruby version for the current shell session
|
||||||
|
|
||||||
|
*rbenv version*::
|
||||||
|
View the currently active Ruby version and where it is set from
|
||||||
|
|
||||||
|
*rbenv versions*::
|
||||||
|
List all locally installed Ruby versions known to rbenv
|
||||||
|
|
||||||
|
*rbenv install* [_<version>_]::
|
||||||
|
(Provided by the *ruby-build* plugin) Download and install a new Ruby version
|
||||||
|
|
||||||
|
*rbenv rehash*::
|
||||||
|
Regenerate shims for all known Ruby executables
|
||||||
|
|
||||||
|
*rbenv which* [_<command>_]::
|
||||||
|
View the executable path that a command resolves to
|
||||||
|
|
||||||
|
*rbenv init*::
|
||||||
|
Help bootstrap rbenv into the current shell environment
|
||||||
|
|
||||||
|
*rbenv help* [_<command>_]::
|
||||||
|
View help text for any rbenv command
|
||||||
|
|
||||||
|
== Environment Variables
|
||||||
|
|
||||||
|
*RBENV_VERSION* (default: read from _.ruby-version_ file)::
|
||||||
|
The Ruby version name to be used
|
||||||
|
|
||||||
|
*RBENV_ROOT* (default: _~/.rbenv_)::
|
||||||
|
The location where rbenv discovers Ruby versions, plugins, and other configuration
|
||||||
|
|
||||||
|
*RBENV_DEBUG*::
|
||||||
|
Activates printing debug information about rbenv internals to standard error
|
||||||
|
|
||||||
|
*RBENV_HOOK_PATH*::
|
||||||
|
Colon-separated list of paths searched for rbenv plugin scripts
|
||||||
|
|
||||||
|
*RBENV_DIR* (default: _$PWD_)::
|
||||||
|
Directory to traverse bottom-up to locate the _.ruby-version_ file
|
||||||
|
|
||||||
|
== Plugins
|
||||||
|
|
||||||
|
As its core functionality, rbenv only switches between Ruby versions and does nothing else, but offers a plugin mechanism to hook into and override almost any aspect of its default behavior.
|
||||||
|
|
||||||
|
The most common plugin for rbenv is *ruby-build* which facilitates installing new Ruby versions into the _$RBENV_ROOT/versions_ directory.
|
||||||
|
|
||||||
|
Read more at https://github.com/rbenv/rbenv/wiki/Plugins
|
||||||
|
|
||||||
|
== Notes
|
||||||
|
|
||||||
|
* https://github.com/rbenv/rbenv/discussions
|
||||||
|
|
||||||
|
* https://github.com/rbenv/rbenv/wiki
|
||||||
|
|
||||||
|
* https://github.com/rbenv/ruby-build#readme
|
||||||
@@ -1,25 +1,8 @@
|
|||||||
CC = @CC@
|
../libexec/rbenv-realpath.dylib:
|
||||||
|
@echo "Warning: this Makefile is obsolete and kept only for backwards compatibility." >&2
|
||||||
CFLAGS = @CFLAGS@
|
@echo "You can remove the \`configure && make ...' step from your rbenv setup." >&2
|
||||||
LOCAL_CFLAGS = @LOCAL_CFLAGS@
|
|
||||||
DEFS = @DEFS@
|
|
||||||
LOCAL_DEFS = @LOCAL_DEFS@
|
|
||||||
|
|
||||||
CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS)
|
|
||||||
|
|
||||||
SHOBJ_CC = @SHOBJ_CC@
|
|
||||||
SHOBJ_CFLAGS = @SHOBJ_CFLAGS@
|
|
||||||
SHOBJ_LD = @SHOBJ_LD@
|
|
||||||
SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@
|
|
||||||
SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@
|
|
||||||
SHOBJ_LIBS = @SHOBJ_LIBS@
|
|
||||||
SHOBJ_STATUS = @SHOBJ_STATUS@
|
|
||||||
|
|
||||||
.c.o:
|
|
||||||
$(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
../libexec/rbenv-realpath.dylib: realpath.o
|
|
||||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ realpath.o $(SHOBJ_LIBS)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o ../libexec/*.dylib
|
rm -f *.o ../libexec/*.dylib
|
||||||
|
|
||||||
|
.PHONY: ../libexec/rbenv-realpath.dylib clean
|
||||||
|
|||||||
31
src/bash.h
31
src/bash.h
@@ -1,31 +0,0 @@
|
|||||||
#ifndef __BASH_H__
|
|
||||||
#define __BASH_H__
|
|
||||||
|
|
||||||
#define EXECUTION_SUCCESS 0
|
|
||||||
#define EXECUTION_FAILURE 1
|
|
||||||
#define EX_USAGE 258
|
|
||||||
|
|
||||||
#define BUILTIN_ENABLED 1
|
|
||||||
|
|
||||||
typedef struct word_desc {
|
|
||||||
char *word;
|
|
||||||
int flags;
|
|
||||||
} WORD_DESC;
|
|
||||||
|
|
||||||
typedef struct word_list {
|
|
||||||
struct word_list *next;
|
|
||||||
WORD_DESC *word;
|
|
||||||
} WORD_LIST;
|
|
||||||
|
|
||||||
typedef int sh_builtin_func_t(WORD_LIST *);
|
|
||||||
|
|
||||||
struct builtin {
|
|
||||||
char *name;
|
|
||||||
sh_builtin_func_t *function;
|
|
||||||
int flags;
|
|
||||||
char * const *long_doc;
|
|
||||||
const char *short_doc;
|
|
||||||
char *unused;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
43
src/configure
vendored
43
src/configure
vendored
@@ -1,46 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# Warning: this configure script is obsolete and kept only for backwards compatibility.
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
src_dir="${0%/*}"
|
src_dir="${0%/*}"
|
||||||
|
|
||||||
if [ -z "$CC" ]; then
|
cp "$src_dir"/Makefile.in "$src_dir"/Makefile
|
||||||
if type -p gcc >/dev/null; then
|
|
||||||
CC=gcc
|
|
||||||
else
|
|
||||||
echo "warning: gcc not found; using CC=cc" >&2
|
|
||||||
CC=cc
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! type -p "$CC" >/dev/null; then
|
|
||||||
echo "aborted: compiler not found: $CC" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$(uname -s)" in
|
|
||||||
Darwin* )
|
|
||||||
host_os="darwin$(uname -r)"
|
|
||||||
;;
|
|
||||||
OpenBSD* )
|
|
||||||
host_os="openbsd$(uname -r)"
|
|
||||||
;;
|
|
||||||
* )
|
|
||||||
host_os="linux-gnu"
|
|
||||||
esac
|
|
||||||
|
|
||||||
eval "$("$src_dir"/shobj-conf -C "$CC" -o "$host_os")"
|
|
||||||
|
|
||||||
sed "
|
|
||||||
s,@CC@,${CC},
|
|
||||||
s,@CFLAGS@,${CFLAGS},
|
|
||||||
s,@LOCAL_CFLAGS@,${LOCAL_CFLAGS},
|
|
||||||
s,@DEFS@,${DEFS},
|
|
||||||
s,@LOCAL_DEFS@,${LOCAL_DEFS},
|
|
||||||
s,@SHOBJ_CC@,${SHOBJ_CC},
|
|
||||||
s,@SHOBJ_CFLAGS@,${SHOBJ_CFLAGS},
|
|
||||||
s,@SHOBJ_LD@,${SHOBJ_LD},
|
|
||||||
s,@SHOBJ_LDFLAGS@,${SHOBJ_LDFLAGS//,/\\,},
|
|
||||||
s,@SHOBJ_XLDFLAGS@,${SHOBJ_XLDFLAGS//,/\\,},
|
|
||||||
s,@SHOBJ_LIBS@,${SHOBJ_LIBS},
|
|
||||||
s,@SHOBJ_STATUS@,${SHOBJ_STATUS},
|
|
||||||
" "$src_dir"/Makefile.in > "$src_dir"/Makefile
|
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
#include "bash.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int realpath_builtin(list)
|
|
||||||
WORD_LIST *list;
|
|
||||||
{
|
|
||||||
int es;
|
|
||||||
char *realbuf, *p;
|
|
||||||
|
|
||||||
if (list == 0) {
|
|
||||||
// builtin_usage();
|
|
||||||
return (EX_USAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (es = EXECUTION_SUCCESS; list; list = list->next) {
|
|
||||||
p = list->word->word;
|
|
||||||
realbuf = realpath(p, NULL);
|
|
||||||
if (realbuf == NULL) {
|
|
||||||
es = EXECUTION_FAILURE;
|
|
||||||
// builtin_error("%s: cannot resolve: %s", p, strerror(errno));
|
|
||||||
} else {
|
|
||||||
printf("%s\n", realbuf);
|
|
||||||
free(realbuf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return es;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *realpath_doc[] = {
|
|
||||||
"Display each PATHNAME argument, resolving symbolic links. The exit status",
|
|
||||||
"is 0 if each PATHNAME was resolved; non-zero otherwise.",
|
|
||||||
(char *)NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
struct builtin realpath_struct = {
|
|
||||||
"realpath",
|
|
||||||
realpath_builtin,
|
|
||||||
BUILTIN_ENABLED,
|
|
||||||
realpath_doc,
|
|
||||||
"realpath pathname [pathname...]",
|
|
||||||
0
|
|
||||||
};
|
|
||||||
558
src/shobj-conf
558
src/shobj-conf
@@ -1,558 +0,0 @@
|
|||||||
#! /bin/sh
|
|
||||||
#
|
|
||||||
# shobj-conf -- output a series of variable assignments to be substituted
|
|
||||||
# into a Makefile by configure which specify system-dependent
|
|
||||||
# information for creating shared objects that may be loaded
|
|
||||||
# into bash with `enable -f'
|
|
||||||
#
|
|
||||||
# usage: shobj-conf [-C compiler] -c host_cpu -o host_os -v host_vendor
|
|
||||||
#
|
|
||||||
# Chet Ramey
|
|
||||||
# chet@po.cwru.edu
|
|
||||||
|
|
||||||
# Copyright (C) 1996-2002 Free Software Foundation, Inc.
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2, or (at your option)
|
|
||||||
# any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program; if not, write to the Free Software
|
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
|
||||||
|
|
||||||
#
|
|
||||||
# defaults
|
|
||||||
#
|
|
||||||
SHOBJ_STATUS=supported
|
|
||||||
SHLIB_STATUS=supported
|
|
||||||
|
|
||||||
SHOBJ_CC=cc
|
|
||||||
SHOBJ_CFLAGS=
|
|
||||||
SHOBJ_LD=
|
|
||||||
SHOBJ_LDFLAGS=
|
|
||||||
SHOBJ_XLDFLAGS=
|
|
||||||
SHOBJ_LIBS=
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS=
|
|
||||||
SHLIB_LIBS=
|
|
||||||
|
|
||||||
SHLIB_DOT='.'
|
|
||||||
SHLIB_LIBPREF='lib'
|
|
||||||
SHLIB_LIBSUFF='so'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF)'
|
|
||||||
SHLIB_DLLVERSION='$(SHLIB_MAJOR)'
|
|
||||||
|
|
||||||
PROGNAME=`basename $0`
|
|
||||||
USAGE="$PROGNAME [-C compiler] -c host_cpu -o host_os -v host_vendor"
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
-C) shift; SHOBJ_CC="$1"; shift ;;
|
|
||||||
-c) shift; host_cpu="$1"; shift ;;
|
|
||||||
-o) shift; host_os="$1"; shift ;;
|
|
||||||
-v) shift; host_vendor="$1"; shift ;;
|
|
||||||
*) echo "$USAGE" >&2 ; exit 2;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
case "${host_os}-${SHOBJ_CC}" in
|
|
||||||
sunos4*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS=-fpic
|
|
||||||
SHOBJ_LD=/usr/bin/ld
|
|
||||||
SHOBJ_LDFLAGS='-assert pure-text'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sunos4*)
|
|
||||||
SHOBJ_CFLAGS=-pic
|
|
||||||
SHOBJ_LD=/usr/bin/ld
|
|
||||||
SHOBJ_LDFLAGS='-assert pure-text'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sunos5*-*gcc*|solaris2*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS=-fpic
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
ld_used=`gcc -print-prog-name=ld`
|
|
||||||
if ${ld_used} -V 2>&1 | grep GNU >/dev/null 2>&1; then
|
|
||||||
# This line works for the GNU ld
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,-h,$@'
|
|
||||||
else
|
|
||||||
# This line works for the Solaris linker in /usr/ccs/bin/ld
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,-i -Wl,-h,$@'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# SHLIB_XLDFLAGS='-R $(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sunos5*|solaris2*)
|
|
||||||
SHOBJ_CFLAGS='-K pic'
|
|
||||||
SHOBJ_LD=/usr/ccs/bin/ld
|
|
||||||
SHOBJ_LDFLAGS='-G -dy -z text -i -h $@'
|
|
||||||
|
|
||||||
# SHLIB_XLDFLAGS='-R $(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
# All versions of Linux or the semi-mythical GNU Hurd.
|
|
||||||
linux*-*|gnu*-*|k*bsd*-gnu-*)
|
|
||||||
SHOBJ_CFLAGS=-fPIC
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,-soname,$@'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-Wl,-rpath,$(libdir) -Wl,-soname,`basename $@ $(SHLIB_MINOR)`'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
freebsd2* | netbsd*)
|
|
||||||
SHOBJ_CFLAGS=-fpic
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS='-x -Bshareable'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-R$(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
# FreeBSD-3.x ELF
|
|
||||||
freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*|dragonfly*)
|
|
||||||
SHOBJ_CFLAGS=-fpic
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
|
|
||||||
if [ -x /usr/bin/objformat ] && [ "`/usr/bin/objformat`" = "elf" ]; then
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,-soname,$@'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-Wl,-rpath,$(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
else
|
|
||||||
SHOBJ_LDFLAGS='-shared'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-R$(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)'
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
# Darwin/MacOS X
|
|
||||||
darwin1*)
|
|
||||||
SHOBJ_STATUS=supported
|
|
||||||
SHLIB_STATUS=supported
|
|
||||||
|
|
||||||
SHOBJ_CFLAGS=''
|
|
||||||
SHLIB_LIBSUFF='dylib'
|
|
||||||
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-dynamiclib'
|
|
||||||
;;
|
|
||||||
|
|
||||||
darwin8*)
|
|
||||||
SHOBJ_STATUS=supported
|
|
||||||
SHLIB_STATUS=supported
|
|
||||||
|
|
||||||
SHOBJ_CFLAGS='-fno-common'
|
|
||||||
|
|
||||||
SHOBJ_LD='MACOSX_DEPLOYMENT_TARGET=10.3 ${CC}'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_MAJOR)$(SHLIB_MINOR).$(SHLIB_LIBSUFF)'
|
|
||||||
SHLIB_LIBSUFF='dylib'
|
|
||||||
|
|
||||||
SHOBJ_LDFLAGS='-undefined dynamic_lookup'
|
|
||||||
SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v'
|
|
||||||
|
|
||||||
SHLIB_LIBS='-lncurses' # see if -lcurses works on MacOS X 10.1
|
|
||||||
;;
|
|
||||||
|
|
||||||
darwin*|macosx*)
|
|
||||||
SHOBJ_STATUS=unsupported
|
|
||||||
SHLIB_STATUS=supported
|
|
||||||
|
|
||||||
SHOBJ_CFLAGS='-fno-common'
|
|
||||||
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_MAJOR)$(SHLIB_MINOR).$(SHLIB_LIBSUFF)'
|
|
||||||
SHLIB_LIBSUFF='dylib'
|
|
||||||
|
|
||||||
case "${host_os}" in
|
|
||||||
darwin[78]*) SHOBJ_LDFLAGS=''
|
|
||||||
SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v'
|
|
||||||
;;
|
|
||||||
*) SHOBJ_LDFLAGS='-dynamic'
|
|
||||||
SHLIB_XLDFLAGS='-arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v'
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
SHLIB_LIBS='-lncurses' # see if -lcurses works on MacOS X 10.1
|
|
||||||
;;
|
|
||||||
|
|
||||||
openbsd*)
|
|
||||||
SHOBJ_CFLAGS=-fPIC
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-R$(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
bsdi2*)
|
|
||||||
SHOBJ_CC=shlicc2
|
|
||||||
SHOBJ_CFLAGS=
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS=-r
|
|
||||||
SHOBJ_LIBS=-lc_s.2.1.0
|
|
||||||
|
|
||||||
# BSD/OS 2.x and 3.x `shared libraries' are too much of a pain in
|
|
||||||
# the ass -- they require changing {/usr/lib,etc}/shlib.map on
|
|
||||||
# each system, and the library creation process is byzantine
|
|
||||||
SHLIB_STATUS=unsupported
|
|
||||||
;;
|
|
||||||
|
|
||||||
bsdi3*)
|
|
||||||
SHOBJ_CC=shlicc2
|
|
||||||
SHOBJ_CFLAGS=
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS=-r
|
|
||||||
SHOBJ_LIBS=-lc_s.3.0.0
|
|
||||||
|
|
||||||
# BSD/OS 2.x and 3.x `shared libraries' are too much of a pain in
|
|
||||||
# the ass -- they require changing {/usr/lib,etc}/shlib.map on
|
|
||||||
# each system, and the library creation process is byzantine
|
|
||||||
SHLIB_STATUS=unsupported
|
|
||||||
;;
|
|
||||||
|
|
||||||
bsdi4*)
|
|
||||||
# BSD/OS 4.x now supports ELF and SunOS-style dynamically-linked
|
|
||||||
# shared libraries. gcc 2.x is the standard compiler, and the
|
|
||||||
# `normal' gcc options should work as they do in Linux.
|
|
||||||
|
|
||||||
SHOBJ_CFLAGS=-fPIC
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,-soname,$@'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-Wl,-soname,`basename $@ $(SHLIB_MINOR)`'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
osf*-*gcc*)
|
|
||||||
# Fix to use gcc linker driver from bfischer@TechFak.Uni-Bielefeld.DE
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,-soname,$@'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-rpath $(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
osf*)
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS='-shared -soname $@ -expect_unresolved "*"'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-rpath $(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
aix4.[2-9]*-*gcc*) # lightly tested by jik@cisco.com
|
|
||||||
SHOBJ_CFLAGS=-fpic
|
|
||||||
SHOBJ_LD='ld'
|
|
||||||
SHOBJ_LDFLAGS='-bdynamic -bnoentry -bexpall'
|
|
||||||
SHOBJ_XLDFLAGS='-G'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-bM:SRE'
|
|
||||||
SHLIB_LIBS='-lcurses -lc'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
aix4.[2-9]*)
|
|
||||||
SHOBJ_CFLAGS=-K
|
|
||||||
SHOBJ_LD='ld'
|
|
||||||
SHOBJ_LDFLAGS='-bdynamic -bnoentry -bexpall'
|
|
||||||
SHOBJ_XLDFLAGS='-G'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-bM:SRE'
|
|
||||||
SHLIB_LIBS='-lcurses -lc'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
#
|
|
||||||
# THE FOLLOWING ARE UNTESTED -- and some may not support the dlopen interface
|
|
||||||
#
|
|
||||||
irix[56]*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS='-fpic'
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,-soname,$@'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-Wl,-rpath,$(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
irix[56]*)
|
|
||||||
SHOBJ_CFLAGS='-K PIC'
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
# SHOBJ_LDFLAGS='-call_shared -hidden_symbol -no_unresolved -soname $@'
|
|
||||||
# Change from David Kaelbling <drk@sgi.com>. If you have problems,
|
|
||||||
# remove the `-no_unresolved'
|
|
||||||
SHOBJ_LDFLAGS='-shared -no_unresolved -soname $@'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-rpath $(libdir)'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
hpux9*-*gcc*)
|
|
||||||
# must use gcc; the bundled cc cannot compile PIC code
|
|
||||||
SHOBJ_CFLAGS='-fpic'
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,+s'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-Wl,+b,$(libdir)'
|
|
||||||
SHLIB_LIBSUFF='sl'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
hpux9*)
|
|
||||||
SHOBJ_STATUS=unsupported
|
|
||||||
SHLIB_STATUS=unsupported
|
|
||||||
|
|
||||||
# If you are using the HP ANSI C compiler, you can uncomment and use
|
|
||||||
# this code (I have not tested it)
|
|
||||||
# SHOBJ_STATUS=supported
|
|
||||||
# SHLIB_STATUS=supported
|
|
||||||
#
|
|
||||||
# SHOBJ_CFLAGS='+z'
|
|
||||||
# SHOBJ_LD='ld'
|
|
||||||
# SHOBJ_LDFLAGS='-b +s'
|
|
||||||
#
|
|
||||||
# SHLIB_XLDFLAGS='+b $(libdir)'
|
|
||||||
# SHLIB_LIBSUFF='sl'
|
|
||||||
# SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
hpux10*-*gcc*)
|
|
||||||
# must use gcc; the bundled cc cannot compile PIC code
|
|
||||||
SHOBJ_CFLAGS='-fpic'
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
# if you have problems linking here, moving the `-Wl,+h,$@' from
|
|
||||||
# SHLIB_XLDFLAGS to SHOBJ_LDFLAGS has been reported to work
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,+s'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-Wl,+h,$@ -Wl,+b,$(libdir)'
|
|
||||||
SHLIB_LIBSUFF='sl'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
hpux10*)
|
|
||||||
SHOBJ_STATUS=unsupported
|
|
||||||
SHLIB_STATUS=unsupported
|
|
||||||
|
|
||||||
# If you are using the HP ANSI C compiler, you can uncomment and use
|
|
||||||
# this code (I have not tested it)
|
|
||||||
# SHOBJ_STATUS=supported
|
|
||||||
# SHLIB_STATUS=supported
|
|
||||||
#
|
|
||||||
# SHOBJ_CFLAGS='+z'
|
|
||||||
# SHOBJ_LD='ld'
|
|
||||||
# SHOBJ_LDFLAGS='-b +s +h $@'
|
|
||||||
#
|
|
||||||
# SHLIB_XLDFLAGS='+b $(libdir)'
|
|
||||||
# SHLIB_LIBSUFF='sl'
|
|
||||||
# SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
hpux11*-*gcc*)
|
|
||||||
# must use gcc; the bundled cc cannot compile PIC code
|
|
||||||
SHOBJ_CFLAGS='-fpic'
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
# SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,-B,symbolic -Wl,+s -Wl,+std -Wl,+h,$@'
|
|
||||||
SHOBJ_LDFLAGS='-shared -fpic -Wl,-b -Wl,+s -Wl,+h,$@'
|
|
||||||
|
|
||||||
SHLIB_XLDFLAGS='-Wl,+b,$(libdir)'
|
|
||||||
SHLIB_LIBSUFF='sl'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
hpux11*)
|
|
||||||
SHOBJ_STATUS=unsupported
|
|
||||||
SHLIB_STATUS=unsupported
|
|
||||||
|
|
||||||
# If you are using the HP ANSI C compiler, you can uncomment and use
|
|
||||||
# this code (I have not tested it)
|
|
||||||
# SHOBJ_STATUS=supported
|
|
||||||
# SHLIB_STATUS=supported
|
|
||||||
#
|
|
||||||
# SHOBJ_CFLAGS='+z'
|
|
||||||
# SHOBJ_LD='ld'
|
|
||||||
# SHOBJ_LDFLAGS='-b +s +h $@'
|
|
||||||
#
|
|
||||||
# SHLIB_XLDFLAGS='+b $(libdir)'
|
|
||||||
# SHLIB_LIBSUFF='sl'
|
|
||||||
# SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
sysv4*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS=-shared
|
|
||||||
SHOBJ_LDFLAGS='-shared -h $@'
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sysv4*)
|
|
||||||
SHOBJ_CFLAGS='-K PIC'
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS='-dy -z text -G -h $@'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sco3.2v5*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS='-fpic' # DEFAULTS TO ELF
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sco3.2v5*)
|
|
||||||
SHOBJ_CFLAGS='-K pic -b elf'
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS='-G -b elf -dy -z text -h $@'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sysv5uw7*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS='-fpic'
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sysv5uw7*)
|
|
||||||
SHOBJ_CFLAGS='-K PIC'
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS='-G -dy -z text -h $@'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sysv5UnixWare*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS=-fpic
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sysv5UnixWare*)
|
|
||||||
SHOBJ_CFLAGS='-K PIC'
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS='-G -dy -z text -h $@'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sysv5OpenUNIX*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS=-fpic
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
sysv5OpenUNIX*)
|
|
||||||
SHOBJ_CFLAGS='-K PIC'
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS='-G -dy -z text -h $@'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
dgux*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS=-fpic
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
dgux*)
|
|
||||||
SHOBJ_CFLAGS='-K pic'
|
|
||||||
SHOBJ_LD=ld
|
|
||||||
SHOBJ_LDFLAGS='-G -dy -h $@'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
msdos*)
|
|
||||||
SHOBJ_STATUS=unsupported
|
|
||||||
SHLIB_STATUS=unsupported
|
|
||||||
;;
|
|
||||||
|
|
||||||
cygwin*)
|
|
||||||
SHOBJ_LD='$(CC)'
|
|
||||||
SHOBJ_LDFLAGS='-shared -Wl,--enable-auto-import -Wl,--enable-auto-image-base -Wl,--export-all -Wl,--out-implib=$(@).a'
|
|
||||||
SHLIB_LIBPREF='cyg'
|
|
||||||
SHLIB_LIBSUFF='dll'
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_DLLVERSION).$(SHLIB_LIBSUFF)'
|
|
||||||
SHLIB_LIBS='$(TERMCAP_LIB)'
|
|
||||||
|
|
||||||
SHLIB_DOT=
|
|
||||||
# For official cygwin releases, DLLVERSION will be defined in the
|
|
||||||
# environment of configure, and will be incremented any time the API
|
|
||||||
# changes in a non-backwards compatible manner. Otherwise, it is just
|
|
||||||
# SHLIB_MAJOR.
|
|
||||||
if [ -n "$DLLVERSION" ] ; then
|
|
||||||
SHLIB_DLLVERSION="$DLLVERSION"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
#
|
|
||||||
# Rely on correct gcc configuration for everything else
|
|
||||||
#
|
|
||||||
*-*gcc*)
|
|
||||||
SHOBJ_CFLAGS=-fpic
|
|
||||||
SHOBJ_LD='${CC}'
|
|
||||||
SHOBJ_LDFLAGS='-shared'
|
|
||||||
|
|
||||||
SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)'
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
SHOBJ_STATUS=unsupported
|
|
||||||
SHLIB_STATUS=unsupported
|
|
||||||
;;
|
|
||||||
|
|
||||||
esac
|
|
||||||
|
|
||||||
echo SHOBJ_CC=\'"$SHOBJ_CC"\'
|
|
||||||
echo SHOBJ_CFLAGS=\'"$SHOBJ_CFLAGS"\'
|
|
||||||
echo SHOBJ_LD=\'"$SHOBJ_LD"\'
|
|
||||||
echo SHOBJ_LDFLAGS=\'"$SHOBJ_LDFLAGS"\'
|
|
||||||
echo SHOBJ_XLDFLAGS=\'"$SHOBJ_XLDFLAGS"\'
|
|
||||||
echo SHOBJ_LIBS=\'"$SHOBJ_LIBS"\'
|
|
||||||
|
|
||||||
echo SHLIB_XLDFLAGS=\'"$SHLIB_XLDFLAGS"\'
|
|
||||||
echo SHLIB_LIBS=\'"$SHLIB_LIBS"\'
|
|
||||||
|
|
||||||
echo SHLIB_DOT=\'"$SHLIB_DOT"\'
|
|
||||||
|
|
||||||
echo SHLIB_LIBPREF=\'"$SHLIB_LIBPREF"\'
|
|
||||||
echo SHLIB_LIBSUFF=\'"$SHLIB_LIBSUFF"\'
|
|
||||||
|
|
||||||
echo SHLIB_LIBVERSION=\'"$SHLIB_LIBVERSION"\'
|
|
||||||
echo SHLIB_DLLVERSION=\'"$SHLIB_DLLVERSION"\'
|
|
||||||
|
|
||||||
echo SHOBJ_STATUS=\'"$SHOBJ_STATUS"\'
|
|
||||||
echo SHLIB_STATUS=\'"$SHLIB_STATUS"\'
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
@@ -87,7 +87,7 @@ OUT
|
|||||||
if [[ \$1 == "-S"* ]]; then
|
if [[ \$1 == "-S"* ]]; then
|
||||||
found="\$(PATH="\${RUBYPATH:-\$PATH}" which \$2)"
|
found="\$(PATH="\${RUBYPATH:-\$PATH}" which \$2)"
|
||||||
# assert that the found executable has ruby for shebang
|
# assert that the found executable has ruby for shebang
|
||||||
if head -1 "\$found" | grep ruby >/dev/null; then
|
if head -n1 "\$found" | grep ruby >/dev/null; then
|
||||||
\$BASH "\$found"
|
\$BASH "\$found"
|
||||||
else
|
else
|
||||||
echo "ruby: no Ruby script found in input (LoadError)" >&2
|
echo "ruby: no Ruby script found in input (LoadError)" >&2
|
||||||
|
|||||||
@@ -5,8 +5,14 @@ load test_helper
|
|||||||
@test "without args shows summary of common commands" {
|
@test "without args shows summary of common commands" {
|
||||||
run rbenv-help
|
run rbenv-help
|
||||||
assert_success
|
assert_success
|
||||||
assert_line "Usage: rbenv <command> [<args>]"
|
assert_line "Usage: rbenv <command> [<args>...]"
|
||||||
assert_line "Some useful rbenv commands are:"
|
assert_line "Commands to manage available Ruby versions:"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "usage flag" {
|
||||||
|
run rbenv-help --usage
|
||||||
|
assert_success
|
||||||
|
assert_output "Usage: rbenv <command> [<args>...]"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "invalid command" {
|
@test "invalid command" {
|
||||||
@@ -65,6 +71,18 @@ SH
|
|||||||
assert_success "Usage: rbenv hello <world>"
|
assert_success "Usage: rbenv hello <world>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "empty usage section" {
|
||||||
|
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||||
|
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||||
|
#!shebang
|
||||||
|
# Summary: Says "hello" to you, from rbenv
|
||||||
|
echo hello
|
||||||
|
SH
|
||||||
|
|
||||||
|
run rbenv-help --usage hello
|
||||||
|
assert_success "Usage: rbenv hello"
|
||||||
|
}
|
||||||
|
|
||||||
@test "multiline usage section" {
|
@test "multiline usage section" {
|
||||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||||
|
|||||||
@@ -43,16 +43,16 @@ ${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash
|
|||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "resolves relative paths" {
|
@test "does not canonicalize paths" {
|
||||||
RBENV_HOOK_PATH="${RBENV_TEST_DIR}/rbenv.d"
|
RBENV_HOOK_PATH="${RBENV_TEST_DIR}/rbenv.d"
|
||||||
create_hook exec "hello.bash"
|
create_hook exec "hello.bash"
|
||||||
mkdir -p "$HOME"
|
mkdir -p "$HOME"
|
||||||
|
|
||||||
RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec
|
RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec
|
||||||
assert_success "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash"
|
assert_success "${RBENV_TEST_DIR}/home/../rbenv.d/exec/hello.bash"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "resolves symlinks" {
|
@test "does not resolve symlinks" {
|
||||||
path="${RBENV_TEST_DIR}/rbenv.d"
|
path="${RBENV_TEST_DIR}/rbenv.d"
|
||||||
mkdir -p "${path}/exec"
|
mkdir -p "${path}/exec"
|
||||||
mkdir -p "$HOME"
|
mkdir -p "$HOME"
|
||||||
@@ -64,7 +64,7 @@ OUT
|
|||||||
RBENV_HOOK_PATH="$path" run rbenv-hooks exec
|
RBENV_HOOK_PATH="$path" run rbenv-hooks exec
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
${HOME}/hola.bash
|
${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash
|
||||||
${RBENV_TEST_DIR}/rbenv.d/exec/bright.sh
|
${RBENV_TEST_DIR}/rbenv.d/exec/world.bash
|
||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|||||||
74
test/init.bats
Normal file → Executable file
74
test/init.bats
Normal file → Executable file
@@ -21,7 +21,7 @@ load test_helper
|
|||||||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||||
run rbenv-init - bash
|
run rbenv-init - bash
|
||||||
assert_success
|
assert_success
|
||||||
assert_line "source '${root}/test/../libexec/../completions/rbenv.bash'"
|
assert_line "source '${root}/test/../completions/rbenv.bash'"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "detect parent shell" {
|
@test "detect parent shell" {
|
||||||
@@ -39,21 +39,77 @@ eval "\$(rbenv-init -)"
|
|||||||
echo \$RBENV_SHELL
|
echo \$RBENV_SHELL
|
||||||
OUT
|
OUT
|
||||||
chmod +x myscript.sh
|
chmod +x myscript.sh
|
||||||
run ./myscript.sh /bin/zsh
|
run ./myscript.sh
|
||||||
assert_success "sh"
|
assert_success "sh"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "setup shell completions (fish)" {
|
@test "skip shell completions (fish)" {
|
||||||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||||
run rbenv-init - fish
|
run rbenv-init - fish
|
||||||
assert_success
|
assert_success
|
||||||
assert_line ". '${root}/test/../libexec/../completions/rbenv.fish'"
|
local line="$(grep '^source' <<<"$output")"
|
||||||
|
[ -z "$line" ] || flunk "did not expect line: $line"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "fish instructions" {
|
@test "set up bash" {
|
||||||
|
assert [ ! -e ~/.bash_profile ]
|
||||||
|
run rbenv-init bash
|
||||||
|
assert_success "writing ~/.bash_profile: now configured for rbenv."
|
||||||
|
run cat ~/.bash_profile
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
assert_line 'eval "$(rbenv init - --no-rehash bash)"'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "set up bash (bashrc)" {
|
||||||
|
mkdir -p "$HOME"
|
||||||
|
touch ~/.bashrc
|
||||||
|
assert [ ! -e ~/.bash_profile ]
|
||||||
|
run rbenv-init bash
|
||||||
|
assert_success "writing ~/.bashrc: now configured for rbenv."
|
||||||
|
run cat ~/.bashrc
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
assert_line 'eval "$(rbenv init - --no-rehash bash)"'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "set up zsh" {
|
||||||
|
unset ZDOTDIR
|
||||||
|
assert [ ! -e ~/.zprofile ]
|
||||||
|
run rbenv-init zsh
|
||||||
|
assert_success "writing ~/.zprofile: now configured for rbenv."
|
||||||
|
run cat ~/.zprofile
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
assert_line 'eval "$(rbenv init - --no-rehash zsh)"'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "set up zsh (zshrc)" {
|
||||||
|
unset ZDOTDIR
|
||||||
|
mkdir -p "$HOME"
|
||||||
|
cat > ~/.zshrc <<<"# rbenv"
|
||||||
|
run rbenv-init zsh
|
||||||
|
assert_success "writing ~/.zshrc: now configured for rbenv."
|
||||||
|
run cat ~/.zshrc
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
assert_line 'eval "$(rbenv init - --no-rehash zsh)"'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "set up fish" {
|
||||||
|
unset XDG_CONFIG_HOME
|
||||||
run rbenv-init fish
|
run rbenv-init fish
|
||||||
assert [ "$status" -eq 1 ]
|
assert_success "writing ~/.config/fish/config.fish: now configured for rbenv."
|
||||||
assert_line 'status --is-interactive; and . (rbenv init -|psub)'
|
run cat ~/.config/fish/config.fish
|
||||||
|
assert_line 'status --is-interactive; and rbenv init - --no-rehash fish | source'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "set up multiple shells at once" {
|
||||||
|
unset ZDOTDIR
|
||||||
|
unset XDG_CONFIG_HOME
|
||||||
|
run rbenv-init bash zsh fish
|
||||||
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
writing ~/.bash_profile: now configured for rbenv.
|
||||||
|
writing ~/.zprofile: now configured for rbenv.
|
||||||
|
writing ~/.config/fish/config.fish: now configured for rbenv.
|
||||||
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "option to skip rehash" {
|
@test "option to skip rehash" {
|
||||||
@@ -73,7 +129,7 @@ OUT
|
|||||||
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
||||||
run rbenv-init - fish
|
run rbenv-init - fish
|
||||||
assert_success
|
assert_success
|
||||||
assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH"
|
assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "can add shims to PATH more than once" {
|
@test "can add shims to PATH more than once" {
|
||||||
@@ -87,7 +143,7 @@ OUT
|
|||||||
export PATH="${RBENV_ROOT}/shims:$PATH"
|
export PATH="${RBENV_ROOT}/shims:$PATH"
|
||||||
run rbenv-init - fish
|
run rbenv-init - fish
|
||||||
assert_success
|
assert_success
|
||||||
assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH"
|
assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "outputs sh-compatible syntax" {
|
@test "outputs sh-compatible syntax" {
|
||||||
|
|||||||
@@ -24,7 +24,22 @@ load test_helper
|
|||||||
assert_success "$RBENV_TEST_DIR"
|
assert_success "$RBENV_TEST_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "prefix for system in /" {
|
||||||
|
mkdir -p "${BATS_TEST_DIRNAME}/libexec"
|
||||||
|
cat >"${BATS_TEST_DIRNAME}/libexec/rbenv-which" <<OUT
|
||||||
|
#!/bin/sh
|
||||||
|
echo /bin/ruby
|
||||||
|
OUT
|
||||||
|
chmod +x "${BATS_TEST_DIRNAME}/libexec/rbenv-which"
|
||||||
|
RBENV_VERSION="system" run rbenv-prefix
|
||||||
|
assert_success "/"
|
||||||
|
rm -f "${BATS_TEST_DIRNAME}/libexec/rbenv-which"
|
||||||
|
}
|
||||||
|
|
||||||
@test "prefix for invalid system" {
|
@test "prefix for invalid system" {
|
||||||
PATH="$(path_without ruby)" run rbenv-prefix system
|
PATH="$(path_without ruby)" run rbenv-prefix system
|
||||||
assert_failure "rbenv: system version not found in PATH"
|
assert_failure <<EOF
|
||||||
|
rbenv: ruby: command not found
|
||||||
|
rbenv: system version not found in PATH"
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ load test_helper
|
|||||||
assert_line 2 "${RBENV_ROOT}/plugins/rbenv-each/bin"
|
assert_line 2 "${RBENV_ROOT}/plugins/rbenv-each/bin"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "RBENV_HOOK_PATH includes etc/rbenv.d folders" {
|
||||||
|
mkdir -p "$RBENV_ROOT"/plugins/rbenv-foo/etc/rbenv.d
|
||||||
|
run rbenv echo -F: "RBENV_HOOK_PATH"
|
||||||
|
assert_line 6 "${RBENV_ROOT}/plugins/rbenv-foo/etc/rbenv.d"
|
||||||
|
}
|
||||||
|
|
||||||
@test "RBENV_HOOK_PATH preserves value from environment" {
|
@test "RBENV_HOOK_PATH preserves value from environment" {
|
||||||
RBENV_HOOK_PATH=/my/hook/path:/other/hooks run rbenv echo -F: "RBENV_HOOK_PATH"
|
RBENV_HOOK_PATH=/my/hook/path:/other/hooks run rbenv echo -F: "RBENV_HOOK_PATH"
|
||||||
assert_success
|
assert_success
|
||||||
|
|||||||
@@ -3,10 +3,11 @@
|
|||||||
load test_helper
|
load test_helper
|
||||||
|
|
||||||
create_executable() {
|
create_executable() {
|
||||||
local bin="${RBENV_ROOT}/versions/${1}/bin"
|
local exe="${RBENV_ROOT}/versions/${1}/bin/${2}"
|
||||||
mkdir -p "$bin"
|
[ -n "$2" ] || exe="$1"
|
||||||
touch "${bin}/$2"
|
mkdir -p "${exe%/*}"
|
||||||
chmod +x "${bin}/$2"
|
touch "$exe"
|
||||||
|
chmod +x "$exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "empty rehash" {
|
@test "empty rehash" {
|
||||||
@@ -104,6 +105,37 @@ ruby
|
|||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "no shims for user-installed gems" {
|
||||||
|
create_executable "2.7.5" "ruby"
|
||||||
|
create_executable "3.1.2" "ruby"
|
||||||
|
create_executable "${HOME}/.gem/ruby/2.7.0/bin/lolcat"
|
||||||
|
create_executable "${HOME}/.gem/ruby/3.1.0/bin/pinecone"
|
||||||
|
|
||||||
|
run rbenv-rehash
|
||||||
|
assert_success ""
|
||||||
|
|
||||||
|
assert [ ! -e "${RBENV_ROOT}/shims/lolcat" ]
|
||||||
|
assert [ ! -e "${RBENV_ROOT}/shims/pinecone" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "explicit gem home" {
|
||||||
|
create_executable "${HOME}/mygems/bin/lolcat"
|
||||||
|
create_executable "${HOME}/mygems/bin/pinecone"
|
||||||
|
|
||||||
|
assert [ ! -e "${RBENV_ROOT}/shims/lolcat" ]
|
||||||
|
assert [ ! -e "${RBENV_ROOT}/shims/pinecone" ]
|
||||||
|
|
||||||
|
GEM_HOME="${HOME}/mygems" run rbenv-rehash
|
||||||
|
assert_success ""
|
||||||
|
|
||||||
|
run ls "${RBENV_ROOT}/shims"
|
||||||
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
lolcat
|
||||||
|
pinecone
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
||||||
@test "carries original IFS within hooks" {
|
@test "carries original IFS within hooks" {
|
||||||
create_hook rehash hello.bash <<SH
|
create_hook rehash hello.bash <<SH
|
||||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||||
|
|||||||
7
test/run
7
test/run
@@ -1,9 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [ -n "$RBENV_NATIVE_EXT" ]; then
|
exec bats ${CI:+--tap} "${@:-test}"
|
||||||
src/configure
|
|
||||||
make -C src
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec bats ${CI:+--tap} test
|
|
||||||
|
|||||||
@@ -2,6 +2,17 @@
|
|||||||
|
|
||||||
load test_helper
|
load test_helper
|
||||||
|
|
||||||
|
@test "shell integration disabled" {
|
||||||
|
run rbenv shell
|
||||||
|
assert_failure "rbenv: shell integration not enabled. Run \`rbenv init' for instructions."
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "shell integration enabled" {
|
||||||
|
eval "$(rbenv init -)"
|
||||||
|
run rbenv shell
|
||||||
|
assert_success "rbenv: no shell-specific version configured"
|
||||||
|
}
|
||||||
|
|
||||||
@test "no shell version" {
|
@test "no shell version" {
|
||||||
mkdir -p "${RBENV_TEST_DIR}/myproject"
|
mkdir -p "${RBENV_TEST_DIR}/myproject"
|
||||||
cd "${RBENV_TEST_DIR}/myproject"
|
cd "${RBENV_TEST_DIR}/myproject"
|
||||||
@@ -20,14 +31,34 @@ load test_helper
|
|||||||
assert_success 'echo "$RBENV_VERSION"'
|
assert_success 'echo "$RBENV_VERSION"'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "shell revert" {
|
||||||
|
RBENV_SHELL=bash run rbenv-sh-shell -
|
||||||
|
assert_success
|
||||||
|
assert_line 0 'if [ -n "${RBENV_VERSION_OLD+x}" ]; then'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "shell revert (fish)" {
|
||||||
|
RBENV_SHELL=fish run rbenv-sh-shell -
|
||||||
|
assert_success
|
||||||
|
assert_line 0 'if set -q RBENV_VERSION_OLD'
|
||||||
|
}
|
||||||
|
|
||||||
@test "shell unset" {
|
@test "shell unset" {
|
||||||
RBENV_SHELL=bash run rbenv-sh-shell --unset
|
RBENV_SHELL=bash run rbenv-sh-shell --unset
|
||||||
assert_success "unset RBENV_VERSION"
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
RBENV_VERSION_OLD="\${RBENV_VERSION-}"
|
||||||
|
unset RBENV_VERSION
|
||||||
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "shell unset (fish)" {
|
@test "shell unset (fish)" {
|
||||||
RBENV_SHELL=fish run rbenv-sh-shell --unset
|
RBENV_SHELL=fish run rbenv-sh-shell --unset
|
||||||
assert_success "set -e RBENV_VERSION"
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
||||||
|
set -e RBENV_VERSION
|
||||||
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "shell change invalid version" {
|
@test "shell change invalid version" {
|
||||||
@@ -42,11 +73,29 @@ SH
|
|||||||
@test "shell change version" {
|
@test "shell change version" {
|
||||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||||
RBENV_SHELL=bash run rbenv-sh-shell 1.2.3
|
RBENV_SHELL=bash run rbenv-sh-shell 1.2.3
|
||||||
assert_success 'export RBENV_VERSION="1.2.3"'
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
RBENV_VERSION_OLD="\${RBENV_VERSION-}"
|
||||||
|
export RBENV_VERSION="1.2.3"
|
||||||
|
OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "shell change version (zsh)" {
|
||||||
|
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||||
|
RBENV_SHELL=zsh run rbenv-sh-shell 1.2.3
|
||||||
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
typeset -g RBENV_VERSION_OLD="\${RBENV_VERSION-}"
|
||||||
|
export RBENV_VERSION="1.2.3"
|
||||||
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "shell change version (fish)" {
|
@test "shell change version (fish)" {
|
||||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||||
RBENV_SHELL=fish run rbenv-sh-shell 1.2.3
|
RBENV_SHELL=fish run rbenv-sh-shell 1.2.3
|
||||||
assert_success 'setenv RBENV_VERSION "1.2.3"'
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
||||||
|
set -gx RBENV_VERSION "1.2.3"
|
||||||
|
OUT
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,6 @@ if [ -z "$RBENV_TEST_DIR" ]; then
|
|||||||
RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv"
|
RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv"
|
||||||
export RBENV_TEST_DIR="$(mktemp -d "${RBENV_TEST_DIR}.XXX" 2>/dev/null || echo "$RBENV_TEST_DIR")"
|
export RBENV_TEST_DIR="$(mktemp -d "${RBENV_TEST_DIR}.XXX" 2>/dev/null || echo "$RBENV_TEST_DIR")"
|
||||||
|
|
||||||
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
|
|
||||||
export RBENV_TEST_DIR="$(realpath "$RBENV_TEST_DIR")"
|
|
||||||
else
|
|
||||||
if [ -n "$RBENV_NATIVE_EXT" ]; then
|
|
||||||
echo "rbenv: failed to load \`realpath' builtin" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
export RBENV_ROOT="${RBENV_TEST_DIR}/root"
|
export RBENV_ROOT="${RBENV_TEST_DIR}/root"
|
||||||
export HOME="${RBENV_TEST_DIR}/home"
|
export HOME="${RBENV_TEST_DIR}/home"
|
||||||
export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d"
|
export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d"
|
||||||
@@ -114,12 +105,12 @@ path_without() {
|
|||||||
local exe="$1"
|
local exe="$1"
|
||||||
local path=":${PATH}:"
|
local path=":${PATH}:"
|
||||||
local found alt util
|
local found alt util
|
||||||
for found in $(which -a "$exe"); do
|
for found in $(type -aP "$exe"); do
|
||||||
found="${found%/*}"
|
found="${found%/*}"
|
||||||
if [ "$found" != "${RBENV_ROOT}/shims" ]; then
|
if [ "$found" != "${RBENV_ROOT}/shims" ]; then
|
||||||
alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
|
alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
|
||||||
mkdir -p "$alt"
|
mkdir -p "$alt"
|
||||||
for util in bash head cut readlink greadlink; do
|
for util in bash head cut readlink greadlink sed sort awk; do
|
||||||
if [ -x "${found}/$util" ]; then
|
if [ -x "${found}/$util" ]; then
|
||||||
ln -s "${found}/$util" "${alt}/$util"
|
ln -s "${found}/$util" "${alt}/$util"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -70,3 +70,19 @@ IN
|
|||||||
run rbenv-version-file-read my-version
|
run rbenv-version-file-read my-version
|
||||||
assert_success "1.9.3"
|
assert_success "1.9.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "prevents directory traversal" {
|
||||||
|
cat > my-version <<<".."
|
||||||
|
run rbenv-version-file-read my-version
|
||||||
|
assert_failure "rbenv: invalid version in \`my-version'"
|
||||||
|
|
||||||
|
cat > my-version <<<"../foo"
|
||||||
|
run rbenv-version-file-read my-version
|
||||||
|
assert_failure "rbenv: invalid version in \`my-version'"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "disallows path segments in version string" {
|
||||||
|
cat > my-version <<<"foo/bar"
|
||||||
|
run rbenv-version-file-read my-version
|
||||||
|
assert_failure "rbenv: invalid version in \`my-version'"
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ setup() {
|
|||||||
|
|
||||||
create_file() {
|
create_file() {
|
||||||
mkdir -p "$(dirname "$1")"
|
mkdir -p "$(dirname "$1")"
|
||||||
touch "$1"
|
echo "system" > "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "detects global 'version' file" {
|
@test "detects global 'version' file" {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ setup() {
|
|||||||
assert_success "system"
|
assert_success "system"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "system version is not checked for existance" {
|
@test "system version is not checked for existence" {
|
||||||
RBENV_VERSION=system run rbenv-version-name
|
RBENV_VERSION=system run rbenv-version-name
|
||||||
assert_success "system"
|
assert_success "system"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "detects local file" {
|
@test "detects local file" {
|
||||||
touch .ruby-version
|
echo "system" > .ruby-version
|
||||||
run rbenv-version-origin
|
run rbenv-version-origin
|
||||||
assert_success "${PWD}/.ruby-version"
|
assert_success "${PWD}/.ruby-version"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ setup() {
|
|||||||
@test "no version selected" {
|
@test "no version selected" {
|
||||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||||
run rbenv-version
|
run rbenv-version
|
||||||
assert_success "system (set by ${RBENV_ROOT}/version)"
|
assert_success "system"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "set by RBENV_VERSION" {
|
@test "set by RBENV_VERSION" {
|
||||||
@@ -36,3 +36,12 @@ setup() {
|
|||||||
run rbenv-version
|
run rbenv-version
|
||||||
assert_success "1.9.3 (set by ${RBENV_ROOT}/version)"
|
assert_success "1.9.3 (set by ${RBENV_ROOT}/version)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "prefer local over global file" {
|
||||||
|
create_version "1.9.3"
|
||||||
|
create_version "3.0.0"
|
||||||
|
cat > ".ruby-version" <<<"1.9.3"
|
||||||
|
cat > "${RBENV_ROOT}/version" <<<"3.0.0"
|
||||||
|
run rbenv-version
|
||||||
|
assert_success "1.9.3 (set by ${PWD}/.ruby-version)"
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ stub_system_ruby() {
|
|||||||
stub_system_ruby
|
stub_system_ruby
|
||||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||||
run rbenv-versions
|
run rbenv-versions
|
||||||
assert_success "* system (set by ${RBENV_ROOT}/version)"
|
assert_success "* system"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "not even system ruby available" {
|
@test "not even system ruby available" {
|
||||||
@@ -42,7 +42,7 @@ stub_system_ruby() {
|
|||||||
run rbenv-versions
|
run rbenv-versions
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
* system (set by ${RBENV_ROOT}/version)
|
* system
|
||||||
1.9
|
1.9
|
||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
@@ -56,15 +56,21 @@ OUT
|
|||||||
@test "multiple versions" {
|
@test "multiple versions" {
|
||||||
stub_system_ruby
|
stub_system_ruby
|
||||||
create_version "1.8.7"
|
create_version "1.8.7"
|
||||||
create_version "1.9.3"
|
create_version "1.9.3-p13"
|
||||||
create_version "2.0.0"
|
create_version "1.9.3-p2"
|
||||||
|
create_version "2.2.10"
|
||||||
|
create_version "2.2.3"
|
||||||
|
create_version "2.2.3-pre.2"
|
||||||
run rbenv-versions
|
run rbenv-versions
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
* system (set by ${RBENV_ROOT}/version)
|
* system
|
||||||
1.8.7
|
1.8.7
|
||||||
1.9.3
|
1.9.3-p2
|
||||||
2.0.0
|
1.9.3-p13
|
||||||
|
2.2.3-pre.2
|
||||||
|
2.2.3
|
||||||
|
2.2.10
|
||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,12 +57,11 @@ create_executable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "doesn't include current directory in PATH search" {
|
@test "doesn't include current directory in PATH search" {
|
||||||
export PATH="$(path_without "kill-all-humans")"
|
|
||||||
mkdir -p "$RBENV_TEST_DIR"
|
mkdir -p "$RBENV_TEST_DIR"
|
||||||
cd "$RBENV_TEST_DIR"
|
cd "$RBENV_TEST_DIR"
|
||||||
touch kill-all-humans
|
touch kill-all-humans
|
||||||
chmod +x kill-all-humans
|
chmod +x kill-all-humans
|
||||||
RBENV_VERSION=system run rbenv-which kill-all-humans
|
PATH="$(path_without "kill-all-humans")" RBENV_VERSION=system run rbenv-which kill-all-humans
|
||||||
assert_failure "rbenv: kill-all-humans: command not found"
|
assert_failure "rbenv: kill-all-humans: command not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,8 +78,7 @@ create_executable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "no executable found for system version" {
|
@test "no executable found for system version" {
|
||||||
export PATH="$(path_without "rake")"
|
PATH="$(path_without "rake")" RBENV_VERSION=system run rbenv-which rake
|
||||||
RBENV_VERSION=system run rbenv-which rake
|
|
||||||
assert_failure "rbenv: rake: command not found"
|
assert_failure "rbenv: rake: command not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +98,28 @@ The \`rspec' command exists in these Ruby versions:
|
|||||||
OUT
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "executable not found in user gems" {
|
||||||
|
create_executable "2.7.6" "ruby"
|
||||||
|
create_executable "${HOME}/.gem/ruby/2.7.0/bin" "rake"
|
||||||
|
GEM_HOME='' RBENV_VERSION=2.7.6 run rbenv-which rake
|
||||||
|
assert_failure
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "executable found in gem home" {
|
||||||
|
create_executable "2.7.6" "ruby"
|
||||||
|
create_executable "${HOME}/mygems/bin" "rake"
|
||||||
|
create_executable "${HOME}/.gem/ruby/2.7.0/bin" "rake"
|
||||||
|
GEM_HOME="${HOME}/mygems" RBENV_VERSION=2.7.6 run rbenv-which rake
|
||||||
|
assert_success "${HOME}/mygems/bin/rake"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "executable found in gem home (system ruby)" {
|
||||||
|
create_executable "${HOME}/mygems/bin" "rbenv-test-lolcat"
|
||||||
|
create_executable "${HOME}/.gem/ruby/2.6.0/bin" "rbenv-test-lolcat"
|
||||||
|
GEM_HOME="${HOME}/mygems" RBENV_VERSION=system run rbenv-which rbenv-test-lolcat
|
||||||
|
assert_success "${HOME}/mygems/bin/rbenv-test-lolcat"
|
||||||
|
}
|
||||||
|
|
||||||
@test "carries original IFS within hooks" {
|
@test "carries original IFS within hooks" {
|
||||||
create_hook which hello.bash <<SH
|
create_hook which hello.bash <<SH
|
||||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||||
@@ -120,6 +140,6 @@ SH
|
|||||||
mkdir -p "$RBENV_TEST_DIR"
|
mkdir -p "$RBENV_TEST_DIR"
|
||||||
cd "$RBENV_TEST_DIR"
|
cd "$RBENV_TEST_DIR"
|
||||||
|
|
||||||
RBENV_VERSION= run rbenv-which ruby
|
RBENV_VERSION='' run rbenv-which ruby
|
||||||
assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby"
|
assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user