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

Compare commits

...

370 Commits

Author SHA1 Message Date
Mislav Marohnić
10e96bfc47 rbenv 1.3.2 2025-01-08 15:05:27 +01:00
Mislav Marohnić
896e76c3d5 Merge pull request #1606 from rbenv/no-readarray
Fix traversing PATH for bash < 4.4
2025-01-08 14:48:03 +01:00
Mislav Marohnić
228fbf4c4f Fix traversing PATH for bash < 4.4
Bash versions before 4.4 did not support the `-d` nor `-t` flags for readarray:
https://lists.gnu.org/archive/html/info-gnu/2016-09/msg00012.html

This switches away from readarray/"read" completely in favor of traversing PATH
by using string substitution.
2025-01-08 14:29:19 +01:00
Mislav Marohnić
84839ae589 rbenv 1.3.1 2025-01-08 00:00:16 +01:00
Mislav Marohnić
75aee988b3 Use static rbenv release version when generating man page 2025-01-07 23:59:22 +01:00
Mislav Marohnić
1d08efe089 Merge pull request #1604 from rbenv/readarray
Use readarray in bash v4+ to avoid rbenv init hanging
2025-01-07 23:52:57 +01:00
Mislav Marohnić
2e3ef01abb Use readarray in bash v4+ to avoid rbenv init hanging
For just a handful of people, rbenv init would hang indefinitely. Turning on
debugging output suggested that the `read` expression to split PATH into a bash
array was hanging, but I could never reproduce this myself. Instead, this uses
bash v4+ `readarray` if it's available, or falls back to bash v3 `read` with the
default DELIM being a newline character. This will cause a regression if any PATH
entries contain a literal newline character, but hopefully people are not relying
on such paths.
2025-01-07 23:40:54 +01:00
Mislav Marohnić
efeab7f8ee Merge pull request #1600 from mikelolasagasti/fix-127
Skip BW01 and BW02 error messages during tests
2024-12-11 18:47:21 +01:00
Mikel Olasagasti Uranga
e5c7eb3399 Skip BW01 and BW02 error messages during tests 2024-12-10 22:03:36 +01:00
Mislav Marohnić
a43095dc11 docs: further clarify the rbenv init command 2024-12-02 18:16:10 +01:00
Mislav Marohnić
4aa904634f Merge pull request #1598 from rbenv/dependabot/github_actions/mislav/bump-homebrew-formula-action-3.2
Bump mislav/bump-homebrew-formula-action from 3.1 to 3.2
2024-11-25 23:25:44 +01:00
dependabot[bot]
4a7d13d7ce Bump mislav/bump-homebrew-formula-action from 3.1 to 3.2
Bumps [mislav/bump-homebrew-formula-action](https://github.com/mislav/bump-homebrew-formula-action) from 3.1 to 3.2.
- [Release notes](https://github.com/mislav/bump-homebrew-formula-action/releases)
- [Commits](https://github.com/mislav/bump-homebrew-formula-action/compare/v3.1...v3.2)

---
updated-dependencies:
- dependency-name: mislav/bump-homebrew-formula-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-25 19:26:27 +00:00
Tom Schraitle
c335ab83de Add /usr/etc/rbenv.d to hooks path (#1587)
The directory /usr/etc is an optional directory and used by
Fedora, RHEL 9, and openSUSE. The purpose of /usr/etc is to store
distribution-provided configuration files that can be overridden
by user-modified files in /etc.

Also used in the sister project pyenv/pyenv#3039

Co-authored-by: Mislav Marohnić <git@mislav.net>
2024-08-27 16:10:43 +02:00
Mislav Marohnić
bf1fcd346b Merge pull request #1583 from nethad/patch-1
Add instructions for Fedora Linux installation
2024-07-16 02:46:42 +02:00
Thomas Ritter
873e0249a5 Fix numbering 2024-07-15 19:56:13 +02:00
Thomas Ritter
d6e547b94e Add instructions for Fedora installation 2024-07-15 19:52:50 +02:00
Mislav Marohnić
3bac268cdb rbenv 1.3.0 2024-07-05 15:02:25 +02:00
Mislav Marohnić
19fa774e42 Merge pull request #1579 from rbenv/no-rehash-default
rbenv init in setup mode defaults to no auto-rehashing
2024-07-05 14:56:58 +02:00
Mislav Marohnić
af03af9593 init: in setup mode, default to --no-rehash
When `rbenv init` is invoked to automatically edit shell startup files,
the generated lines will be invoking `rbenv init - --no-rehash` by default
to help speed up shell startup. Auto-rehashing on every shell startup can
be slow for some users but is not crucial to rbenv operation. Lets assume
that rbenv shims are already healthy and that they will be regenerated as
needed after installing new ruby versions and gems.
2024-07-05 14:44:17 +02:00
Mislav Marohnić
1fcb988164 readme: add some warnings 2024-07-05 14:39:31 +02:00
Mislav Marohnić
925e5ad0e7 Merge pull request #1575 from rbenv/readme-brew-install
Removes redundant ruby-build from brew-install
2024-07-05 14:16:28 +02:00
Jason Karns
35960ee19e Removes redundant ruby-build from brew-install
This was already put in place by https://github.com/rbenv/rbenv/pull/863 but regressed with e4f61e67e2

(And ruby-build is still included in rbenv's formula)
2024-05-27 21:16:06 -04:00
Mislav Marohnić
c3ba994ec2 rbenv init: modify shell config files instead of printing instructions (#1568)
When running `rbenv init`, typically during rbenv setup, users expected
their shell environment to be modified permanently. Instead, what the
command would do is print the instructions to the user and expect them
to edit their shell initialization files accordingly. This proved to
be unintuitive.

Now, running `rbenv init <shells>...` will modify the shell initialization
files of the following shells:

- bash: `~/.bash_profile` or `~/.bashrc` if the latter exists but the former does not
- zsh: `~/.zprofile` or `~/.zshrc` if the latter exists and mentions "rbenv"
- fish: `~/.config/fish/config.fish`

If no shells were specified on the command line, rbenv will try to detect
the current shell.

It should be safe to run `rbenv init` multiple times, as the command will
avoid modifying any shell startup file that already mentions "rbenv init".
2024-05-03 16:59:39 +02:00
Farid NL
a3b98a4223 Use compsys completion system for zsh (#1569)
The new `_rbenv` script will be autoloaded by zsh as long as it's found in $FPATH.
It should be the package manager's responsibility to symlink or move this file
into an appropriate location.

Co-authored-by: Mislav Marohnić <git@mislav.net>
2024-05-03 16:57:16 +02:00
Mislav Marohnić
ac020225c2 Clarify help text of some commands (#1567) 2024-04-29 14:20:47 +02:00
Mislav Marohnić
f2ac882579 rbenv shell: properly declare global variables for zsh (#1566)
With zsh `setopt warn_create_global` the "shell" command used to cause
a warning message:

    scalar parameter RBENV_VERSION_OLD created globally in function rbenv.

By using `typeset -g` specifically for zsh, this warning goes away.
2024-04-29 14:20:21 +02:00
Hiroshi SHIBATA
e8b7a27ee6 Merge pull request #1544 from acook/patch-1
Update link to maintained version of Bats
2023-12-25 12:49:41 +09:00
Hiroshi SHIBATA
8d0ca21451 Merge pull request #1545 from rbenv/use-bats-core
Use bats-core instead of archived version
2023-12-25 12:49:09 +09:00
Hiroshi SHIBATA
d7a5e87d75 Use bats-core instead of archived version 2023-12-25 12:41:47 +09:00
Anthony M. Cook
5cae73944f Update link to maintained version of Bats 2023-12-23 17:50:44 -06:00
benmelz
325abac17d Move gem-rehash monkey patch (#1541)
The `rubygems_plugin.rb` file doesn't get loaded until after `Bundler::Installer.install` is called, so target `Bundler::Installer#install` to fix invocation order issues.

Co-authored-by: Mislav Marohnić <git@mislav.net>
2023-12-09 21:14:40 +01:00
Mislav Marohnić
d10388a052 Merge pull request #1537 from dipree/dipree/update-alerts-readme
Update alerts in README
2023-11-21 15:22:17 +01:00
Daniel Adams
7c4350edf4 Update alerts in README 2023-11-20 13:21:43 +01:00
Hiroshi SHIBATA
d6bb1c6396 Merge pull request #1533 from rbenv/dependabot/github_actions/redhat-plumbers-in-action/differential-shellcheck-5
Bump redhat-plumbers-in-action/differential-shellcheck from 4 to 5
2023-10-10 11:16:39 +09:00
dependabot[bot]
ad6544409b Bump redhat-plumbers-in-action/differential-shellcheck from 4 to 5
Bumps [redhat-plumbers-in-action/differential-shellcheck](https://github.com/redhat-plumbers-in-action/differential-shellcheck) from 4 to 5.
- [Release notes](https://github.com/redhat-plumbers-in-action/differential-shellcheck/releases)
- [Changelog](https://github.com/redhat-plumbers-in-action/differential-shellcheck/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/redhat-plumbers-in-action/differential-shellcheck/compare/v4...v5)

---
updated-dependencies:
- dependency-name: redhat-plumbers-in-action/differential-shellcheck
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-09 18:58:48 +00:00
Hiroshi SHIBATA
ae8a0ee125 Merge pull request #1531 from rbenv/dependabot/github_actions/mislav/bump-homebrew-formula-action-3.1
Bump mislav/bump-homebrew-formula-action from 3.0 to 3.1
2023-10-03 09:07:25 +09:00
dependabot[bot]
3646eb840b Bump mislav/bump-homebrew-formula-action from 3.0 to 3.1
Bumps [mislav/bump-homebrew-formula-action](https://github.com/mislav/bump-homebrew-formula-action) from 3.0 to 3.1.
- [Release notes](https://github.com/mislav/bump-homebrew-formula-action/releases)
- [Commits](https://github.com/mislav/bump-homebrew-formula-action/compare/v3.0...v3.1)

---
updated-dependencies:
- dependency-name: mislav/bump-homebrew-formula-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-02 18:52:50 +00:00
Hiroshi SHIBATA
6e58140657 Merge pull request #1530 from rbenv/dependabot/github_actions/mislav/bump-homebrew-formula-action-3.0
Bump mislav/bump-homebrew-formula-action from 2.3 to 3.0
2023-09-27 14:50:05 +09:00
dependabot[bot]
a7e508fcdf Bump mislav/bump-homebrew-formula-action from 2.3 to 3.0
Bumps [mislav/bump-homebrew-formula-action](https://github.com/mislav/bump-homebrew-formula-action) from 2.3 to 3.0.
- [Release notes](https://github.com/mislav/bump-homebrew-formula-action/releases)
- [Commits](https://github.com/mislav/bump-homebrew-formula-action/compare/v2.3...v3.0)

---
updated-dependencies:
- dependency-name: mislav/bump-homebrew-formula-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-25 18:48:03 +00:00
Hiroshi SHIBATA
d1f1865c2a Merge pull request #1526 from rbenv/dependabot/github_actions/mislav/bump-homebrew-formula-action-2.3
Bump mislav/bump-homebrew-formula-action from 2.2 to 2.3
2023-09-19 10:03:53 +09:00
dependabot[bot]
86b5797083 Bump mislav/bump-homebrew-formula-action from 2.2 to 2.3
Bumps [mislav/bump-homebrew-formula-action](https://github.com/mislav/bump-homebrew-formula-action) from 2.2 to 2.3.
- [Release notes](https://github.com/mislav/bump-homebrew-formula-action/releases)
- [Commits](https://github.com/mislav/bump-homebrew-formula-action/compare/v2.2...v2.3)

---
updated-dependencies:
- dependency-name: mislav/bump-homebrew-formula-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-18 18:45:56 +00:00
Hiroshi SHIBATA
5d78e47399 Merge pull request #1521 from rbenv/dependabot/github_actions/actions/checkout-4
Bump actions/checkout from 3 to 4
2023-09-05 08:35:57 +09:00
dependabot[bot]
59acc42647 Bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-04 18:44:47 +00:00
Mislav Marohnić
4fec76f267 Merge pull request #1515 from rbenv/help-usage
help: have `--usage` always print a usage line
2023-07-14 23:29:47 +02:00
Mislav Marohnić
592fe6a087 help: have --usage always print a usage line 2023-07-11 18:54:38 +02:00
Richie Thomas
906a6acc10 version-file docs update (#1512)
Update rbenv-version-file docs to indicate that the returned version file may or may not actually exist.

Co-authored-by: Mislav Marohnić <git@mislav.net>
2023-07-11 17:38:36 +02:00
Mislav Marohnić
3112172081 Merge pull request #1504 from kpschoedel/ksh-versions
Support ksh versions
2023-06-21 12:06:55 +02:00
Kevin Schoedel
cfe1c37d26 Add explanatory comment, and remove obsolete versions 2023-05-13 12:56:22 -04:00
Hiroshi SHIBATA
af9201ea1e Merge pull request #1505 from notEthan/comment-link-fix
Fix a dead link in a comment
2023-05-13 16:45:46 +09:00
Ethan
56512aee3b fix dead link in comment 2023-05-13 00:14:21 -07:00
Kevin Schoedel
e390b228c8 Support ksh versions
Korn shell had two major versions: ’88 and ’93. Some systems have ksh
installed under the name `ksh93`. A few systems (maybe only Solaris
now) also have a `ksh88`. A few others use the `pdksh` (roughly ’88)
or `mksh` (roughly ’93) implementations, originated before ksh was
open source.

As far as the (very minor) use in rbenv is concerned, these are all
equivalent. This change accepts all of the above.

Tested with `ksh93`, `pdksh`, and `mksh`.
2023-05-11 12:23:34 -04:00
Mislav Marohnić
a632465cf4 Merge pull request #1497 from jamacku/patch-1
ci: trigger differential-shellcheck workflow on push
2023-03-31 11:19:33 +02:00
Jan Macku
54744db05e ci: trigger differential-shellcheck workflow on push
Fixes: redhat-plumbers-in-action/differential-shellcheck#215
2023-03-31 10:14:01 +02:00
Richie Thomas
dd79c11f6c Add spec to cover inclusion of etc/ sub-folders in plugins test (#1492) 2023-03-27 15:51:59 +02:00
Mislav Marohnić
0704e65781 Fix resolving rbenv symlink to its final location (#1482)
1. On systems with `readlink -f`, use that to canonicalize the path to libexec directory;
2. Otherwise, resolve symlinks recursively rather than just once.
2023-02-15 17:09:20 +01:00
Hiroshi SHIBATA
8644fb5519 Merge pull request #1478 from rbenv/dependabot/github_actions/redhat-plumbers-in-action/differential-shellcheck-4
Bump redhat-plumbers-in-action/differential-shellcheck from 3 to 4
2023-02-08 09:38:12 +09:00
Hiroshi SHIBATA
41e242857e Merge pull request #1477 from rbenv/dependabot/github_actions/mislav/bump-homebrew-formula-action-2.2
Bump mislav/bump-homebrew-formula-action from 1.4 to 2.2
2023-02-08 09:36:21 +09:00
dependabot[bot]
6f21f76965 Bump redhat-plumbers-in-action/differential-shellcheck from 3 to 4
Bumps [redhat-plumbers-in-action/differential-shellcheck](https://github.com/redhat-plumbers-in-action/differential-shellcheck) from 3 to 4.
- [Release notes](https://github.com/redhat-plumbers-in-action/differential-shellcheck/releases)
- [Changelog](https://github.com/redhat-plumbers-in-action/differential-shellcheck/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/redhat-plumbers-in-action/differential-shellcheck/compare/v3...v4)

---
updated-dependencies:
- dependency-name: redhat-plumbers-in-action/differential-shellcheck
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-08 00:34:53 +00:00
dependabot[bot]
8be1b9bd0e Bump mislav/bump-homebrew-formula-action from 1.4 to 2.2
Bumps [mislav/bump-homebrew-formula-action](https://github.com/mislav/bump-homebrew-formula-action) from 1.4 to 2.2.
- [Release notes](https://github.com/mislav/bump-homebrew-formula-action/releases)
- [Commits](https://github.com/mislav/bump-homebrew-formula-action/compare/v1.4...v2.2)

---
updated-dependencies:
- dependency-name: mislav/bump-homebrew-formula-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-08 00:34:48 +00:00
Hiroshi SHIBATA
7eafc5fe02 Merge pull request #1476 from rbenv/dependabot
Added dependabot update for GitHub Actions
2023-02-08 09:20:43 +09:00
Hiroshi SHIBATA
9fe4cb8e1e Added dependabot update for GitHub Actions 2023-02-08 09:17:02 +09:00
Hiroshi SHIBATA
61747c06d4 Merge pull request #1468 from ahangarha/patch-1
Improve disabling instruction
2022-12-19 07:42:58 +09:00
Mostafa Ahangarha
7509eafdd0 Improve disabling instruction
Though this is a minor change, I think it is good to have it. It is better to commend a line in config files to disable something than to remove it.
2022-12-16 17:49:24 +03:30
Hiroshi SHIBATA
593f820a7d Merge pull request #1465 from jamacku/patch-1
ci(lint): pin `differential-shellcheck` to `v3` tag
2022-12-10 05:29:43 +09:00
Jan Macku
5c12600625 ci(lint): pin differential-shellcheck to v3 tag 2022-12-09 13:38:54 +01:00
Mislav Marohnić
6717c62dc1 Merge pull request #1461 from ydah/update_actions-checkput
Update actions/checkout version to v3
2022-11-22 17:33:14 +01:00
ydah
5f9c0ba613 Update actions/checkout version to v3
The version 3.x appears to be due to the following:
- https://github.com/actions/checkout/pull/689

There have been no breaking changes, and we seem to have no problem keeping up with the latest version.
2022-11-22 23:48:26 +09:00
Mislav Marohnić
52acbdf83f Merge pull request #1456 from richiethomas/master
`rbenv version`- test coverage for preferring local over global version file
2022-10-17 13:47:27 +02:00
Richie Thomas
85f304ef3b Prefer local over global version file 2022-10-15 11:11:48 -05:00
Mislav Marohnić
41580b69db Merge pull request #1448 from rbenv/command-to-type-P
Ignore shell builtins and functions when looking up commands in PATH
2022-10-09 14:49:32 +02:00
Mislav Marohnić
3e5347be1e Make the usage syntax for arbitrary args consistent (#1447) 2022-10-09 14:49:15 +02:00
Mislav Marohnić
172a79e993 Merge pull request #1449 from rbenv/libexec-vs-bin
Avoid assuming rbenv original project layout
2022-10-09 14:48:53 +02:00
Mislav Marohnić
8275e15cb0 Use read -a to split output into an array (#1450) 2022-10-09 14:48:13 +02:00
Mislav Marohnić
90c0357682 Merge pull request #1453 from rbenv/update-manpage
Consistent syntax in man page
2022-10-09 14:47:57 +02:00
Mislav Marohnić
30aaf4edba Consistent syntax in man page 2022-10-09 13:57:07 +02:00
Mislav Marohnić
d97713d1b5 Avoid assuming rbenv original project layout
Someone packaging rbenv might choose to place the `bin` and `libexec` directories separately.
2022-10-07 16:38:28 +02:00
Mislav Marohnić
43e30ef815 Ignore shell builtins and functions when looking up commands in PATH
Weirdly, `command -v true` returns `true` instead of `/usr/bin/true`.
2022-10-07 16:34:38 +02:00
Mislav Marohnić
6b1cc34610 Merge pull request #1445 from rbenv/allow-userinstall-warning
Restore Rubygems warning for user-installed gems
2022-10-07 13:17:35 +02:00
Mislav Marohnić
d2d3012f17 Restore Rubygems warning for user-installed gems 2022-10-07 13:02:18 +02:00
Mislav Marohnić
410e05bf8c Revert support for user-installed gems (#1443) 2022-10-07 12:56:54 +02:00
Mislav Marohnić
a6cf6aeadb Merge pull request #1440 from rbenv/type-P
Test for executables but not functions
2022-09-30 18:30:08 +02:00
Mislav Marohnić
8406a2bc7f Test for executables but not functions 2022-09-30 12:29:49 +02:00
Mislav Marohnić
ed1a3a5545 Switch back to resolving symlinks for rbenv executable (#1439)
Considerations:

- `./libexec/rbenv` executable is the entrypoint to the program;

- BASH_SOURCE might be the path to a symlink that has activated `./libexec/rbenv`;

- We must resolve the symlink to learn where rbenv's libexec directory is;

- It's not guaranteed that rbenv commands will always remain directly under their own "libexec" directory, since a package maintainer can change that, e.g. rbenv commands are sometimes placed into `/usr/libexec/rbenv/*`;

- Resolving symlinks might fail and in that case we just assume rbenv project layout.
2022-09-29 15:27:17 +02:00
Mislav Marohnić
22ee5d4175 Add man page (#1438)
`rbenv help` without arguments now runs `man rbenv` on systems where man is present.
2022-09-27 02:17:50 +02:00
Mislav Marohnić
7c7c4dc11c Delete CNAME 2022-09-26 16:15:55 +02:00
Mislav Marohnić
45ae8d2ebc Create CNAME 2022-09-26 16:15:21 +02:00
Mislav Marohnić
396e65a461 Add note about troubleshooting BUILD FAILED 2022-09-26 03:14:36 +02:00
Mislav Marohnić
959968c46d Support GEM_HOME, add limited support for user-installed gems (#1436)
The rehash process will now discover executables in additional locations:
- `~/.gem/ruby/<version>/bin/*`
- `$GEM_HOME/bin`

The `rbenv which` (and thus `rbenv exec`) command will also search these locations when looking up a command. This enables shims to dispatch calls to executables added by `gem install --user-install`.

Note that this support is limited:
- It will only work with C Ruby, as it's difficult to guess the `~/.gem/<engine>/<version>` directory for other Rubies without actually loading Ruby;
- It will only work for RBENV_VERSION values in the format `X.Y.Z` and not "system".
2022-09-26 02:57:15 +02:00
Mislav Marohnić
009ef3a2db Undo collapsable installation instructions
The resulting UI seemed simpler but was harder to interact with.
2022-09-25 23:26:02 +02:00
Mislav Marohnić
acdd8a95bd Fix wiki link, add note about plugins 2022-09-25 23:24:05 +02:00
Mislav Marohnić
98412dba80 Merge pull request #1434 from rbenv/init-path
Use absolute path in `rbenv init` instructions if needed
2022-09-25 22:55:44 +02:00
Mislav Marohnić
6426f852d0 Use absolute path in rbenv init instructions if needed 2022-09-25 22:32:46 +02:00
Mislav Marohnić
33f8621ec8 Massive README overhaul (#1433)
rbenv is now the most popular Ruby version manager, so we don't need to
sell it so hard. Instead, help the reader find installation and usage
instructions more easily.

The installation instructions are now simpler and pointing out that
ruby-build needs a separate install is now done in the "Installing Ruby
versions" section.

Finally, link to a wiki doc about potential downsides of rbenv along
with the comparison of different version manager tools.
2022-09-25 00:08:32 +02:00
Mislav Marohnić
9572edf4bb Init script automatically adds rbenv to PATH if necessary (#1432) 2022-09-24 23:59:13 +02:00
Mislav Marohnić
117a381575 Simplify resolving symlinks, remove native extension (#1428) 2022-09-22 11:34:02 +02:00
Jan Macku
56a440e4a7 Add Shell linter - Differential-ShellCheck (#1419)
Signed-off-by: Jan Macku <jamacku@redhat.com>
Co-authored-by: Mislav Marohnić <git@mislav.net>
2022-09-18 23:57:43 +02:00
Richie Thomas
a8ecfc743e Make zsh tab completion more resilient against user's shell configuration (#1422)
Ensure a zsh user's prior shell options don't interfere with indexing into an array of arguments
2022-09-15 18:59:26 +02:00
Hiroshi SHIBATA
c4395e5820 Merge pull request #1418 from uraitakahito/patch-0
Fix link to Pow because the server is down
2022-07-16 08:14:44 +09:00
Takahito Urai
a54b47e783 Fix link to Pow because the server is down 2022-07-15 21:46:32 +09:00
Mislav Marohnić
c6cc0a1959 Merge pull request #1393 from scop/refactor/simplify-version-file-read
Simplify version file read
2022-03-09 13:03:36 +01:00
Ville Skyttä
b39d4291be Simplify version file read
Avoid a subshell and external `cut` invocation, as well as a throwaway
intermediate array.
2022-03-08 21:10:15 +02:00
Ville Skyttä
cec6d46792 Don't bother reading empty version files 2022-03-08 20:56:22 +02:00
Mislav Marohnić
e4f61e67e2 Fix indentation in installation instructions 2022-02-18 22:36:23 +01:00
Mislav Marohnić
42aa760e2e Merge pull request #1388 from tommyjanna/readme
Redirect Debian/Ubuntu users to install using git
2022-02-18 22:26:50 +01:00
tommyjanna
d2c527cdd7 Redirect Debian/Ubuntu users to install using git
Resolves #1347
2022-02-18 15:36:53 -05:00
Mislav Marohnić
a76c4aaafa Merge pull request #1379 from dmerejkowsky/grammar-fix
README: grammar fix
2022-01-17 17:23:26 +01:00
Dimitri Merejkowsky
5b5c60fb6e README: grammar fix 2022-01-17 15:17:20 +01:00
Hiroshi SHIBATA
304cb7b6a7 Merge pull request #1359 from scop/which-a-to-type-aP
Use test -aP instead of which -a in test helper
2021-11-17 21:36:16 +09:00
Mislav Marohnić
25fdc1caf9 Remove the word "groom" from documentation
Fixes #1361
2021-11-17 13:28:39 +01:00
Hiroshi SHIBATA
264cb65a1e Merge pull request #1360 from simonschaufi/patch-1
Make bash commands copy-able by GitHub
2021-11-17 09:24:47 +09:00
Simon Schaufelberger
00d93c1d91 Make bash commands copy-able by GitHub
In order to be able to copy the commands, remove the `$`
2021-11-16 16:11:00 +01:00
Ville Skyttä
68fca03bb8 Use test -aP instead of which -a in test helper
The former is a bash builtin, latter not necessarily available. For
example, `which` is deprecated in Debian's debianutils >= 5.0.
2021-11-11 18:46:44 +02:00
Audree Steinberg
6cc7bff383 Update code block in readme for rbenv-doctor script (#1353)
Co-authored-by: Mislav Marohnić <git@mislav.net>
2021-10-21 15:23:46 +02:00
Mislav Marohnić
38e1fbb08e rbenv 1.2.0 2021-09-29 20:47:10 +02:00
Mislav Marohnić
69323e77cc Clarify bash config for Ubuntu Desktop vs. other platforms
Fixes #1130
2021-09-29 20:23:42 +02:00
Mislav Marohnić
526f2de13d Merge pull request #1111 from prrrnd/prrrnd/versions-sorted-semantically
Sort versions semantically in rbenv versions
2021-09-29 20:09:57 +02:00
Mislav Marohnić
28cd6f123e 💅 Clean up version sorting and add test 2021-09-29 20:07:47 +02:00
prrrnd
d3d4606d2f Sort versions semantically in rbenv versions 2021-09-29 20:07:04 +02:00
Mislav Marohnić
0767d64344 Merge pull request #1350 from rbenv/rehash-path-to-rbenv
Have shims survive upgrades via Homebrew
2021-09-29 20:02:24 +02:00
Mislav Marohnić
76e64ff2ea Have shims survive symlinked rbenv updates a la Homebrew
Homebrew places the rbenv executable in a location such as
`/usr/local/bin/rbenv`, which is in PATH. However, that is a symlink to
`/usr/local/Cellar/rbenv/<VERSION>/bin/rbenv`, which is itself a symlink to
`/usr/local/Cellar/rbenv/<VERSION>/libexec/rbenv`. Upon executing, rbenv
will add its own directory to PATH so that it can easily invoke its
subcommands.

When generating shims during `rbenv rehash`, rbenv will try to put the
absolute path to itself inside each shim so that shims would work even
if rbenv itself isn't in PATH. Under Homebrew, rbenv's directory will be
the versioned directory in Homebrew's Cellar. However, due to Homebrew's
auto-cleanup functionality, shims generated this way will be broken
after upgrading rbenv because of the versioned Cellar path.

This changes how rbenv discovers itself in PATH: it will look at the
original PATH, not in the one modified by rbenv, with the intention of
excluding results under rbenv's own `libexec/`. If rbenv wasn't found in
PATH, return the absolute path to rbenv's own `bin/rbenv`.
2021-09-29 19:54:36 +02:00
Mislav Marohnić
b0fb351419 GitHub now auto-generates a Table of Contents 2021-09-28 13:41:20 +02:00
Mislav Marohnić
e7fd07dd91 Merge pull request #1334 from rbenv/rehash-speedup
Speed up rehash
2021-09-28 13:25:38 +02:00
Mislav Marohnić
faf999211b Speed up rehash
Before (20 ruby versions, producing 200 shims total):

    mean:    0.124 s
    stdev:   0.003

After:

    mean:    0.090 s
    stdev:   0.004
2021-05-11 11:51:00 +02:00
Mislav Marohnić
585ed84283 Merge pull request #1099 from blueyed/init-shell
Improve init: warn about missing shell and use it in the template
2021-05-06 00:46:43 +02:00
Daniel Hahler
d061cb4651 Have rbenv init print instructions that hardcode the detected shell
This speeds up subsequent `rbenv init -` executions for the user who
followed these instructions because the shell will no longer have to be
detected each time.
2021-05-06 00:43:16 +02:00
Mislav Marohnić
059bb2c151 Merge pull request #1243 from scop/nounset
Make work in set -u (nounset) mode
2021-05-06 00:13:20 +02:00
Mislav Marohnić
b904ea54cc Merge pull request #1332 from rbenv/head-flag
Supply `head -n` flag explicitly
2021-05-06 00:10:23 +02:00
Mislav Marohnić
dcba8b4064 Supply head -n flag explicitly
The syntax `head -NUM` was deprecated in the POSIX standard.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html
2021-05-05 22:42:56 +02:00
Jason Karns
633436706f Merge pull request #1331 from AmritD/patch-1
Updated rbenv-doctor url to reflect renaming master branch to main
2021-05-04 16:22:48 -04:00
Jason Karns
4092eba274 Update rbenv-doctor link master -> main 2021-05-04 16:20:33 -04:00
Amrit Dhakal
064e1c48ba Updated rbenv-doctor url to reflect renaming master branch to main
Updated rbenv-doctor url to reflect renaming master branch to main
2021-05-04 09:46:36 -04:00
Hiroshi SHIBATA
462bb67709 Merge pull request #1330 from neilparikh/patch-1
Fix link to rbenv-doctor
2021-05-04 15:53:11 +09:00
Neil Parikh
b424d452d0 Fix link to rbenv-doctor
master -> main
2021-05-04 02:03:11 -04:00
Hiroshi SHIBATA
80af359232 Merge pull request #1307 from native-api/ps4
Use a better PS4 as recommeneded by Bash Hackers Wiki
2021-04-27 13:30:49 +09:00
Hiroshi SHIBATA
ccb4601f3a Merge pull request #1311 from scop/shell-detect-improvements
Shell detect improvements
2021-04-27 13:14:58 +09:00
Hiroshi SHIBATA
5d6f998c52 Merge pull request #1320 from scop/test/misleading-parent-shell-arg
test(init): remove misleading arg in detect from parent shell case
2021-04-27 13:14:42 +09:00
Ville Skyttä
6b842a7670 test(init): remove misleading arg in detect from parent shell case
The generated script does not take/use any arguments, so passing
/bin/zsh to it serves only to cause confusion.
2021-03-23 23:41:55 +02:00
Ville Skyttä
45951d2cbb feat(init): strip -<suffix> when autodetecting shell
For example bash-5.1, bash-static.
2021-03-01 07:49:47 +02:00
Hiroshi SHIBATA
d604acb78a Merge pull request #1308 from avronr/patch-2
[DOCS] Typo and formatting fix.
2021-02-12 07:49:56 +09:00
Abraham Raji
37405c3249 [DOCS] Typo and formatting fix.
- fixing typos and formatting issues.
2021-02-12 03:47:31 +05:30
Hiroshi SHIBATA
268c61a69c Merge pull request #1289 from avronr/patch-1
Update README.md
2021-02-11 08:32:34 +09:00
Ivan Pozdeev
b5429624c2 Use a better PS4 as recommeneded by Bash Hackers Wiki
it allows to see functions as well as lines, therefore making it possible to see the control flow
2021-02-10 22:46:08 +03:00
Abraham Raji
5f7597e754 Update README.md
Added Installation and uninstallation instructions for Debian and Arch Linux Family
Give a little more details about Ubuntu's .bash_profile issue
2020-12-15 21:08:56 +05:30
Hiroshi SHIBATA
62d7798270 Merge pull request #1015 from advaitju/master
Documentation unclear about installing Ruby version
2020-12-03 13:45:17 +09:00
Hiroshi SHIBATA
4086bbe562 Merge pull request #1119 from blueyed/test-run
test/run: handle optional paths/args for bats
2020-12-03 13:41:17 +09:00
Hiroshi SHIBATA
60c9339685 Merge pull request #1275 from metalefty/readme
README: reflect changes in rbenv/ruby-build#1402
2020-10-19 15:59:40 +09:00
Koichiro IWAO
d3f8de4c04 README: reflect changes in rbenv/ruby-build#1402 2020-10-19 15:31:05 +09:00
Hiroshi SHIBATA
0843745be9 Merge pull request #1253 from scop/bash-completion-globbing
bash completion: avoid unintentional globbing
2020-08-09 08:13:04 +09:00
Jason Karns
d4d69ed0cd Merge pull request #1260 from rbenv/rename-conduct-1
Rename CONDUCT.md to CODE_OF_CONDUCT.md
2020-08-03 12:24:53 -04:00
Jason Karns
0493a33f59 Rename CONDUCT.md to CODE_OF_CONDUCT.md
GitHub's expected filename is CODE_OF_CONDUCT.md. Whether that is the best name or even the current de facto standard is to be debated. But moving forward, this is likely the filename that will become the most common within the community, as that is the name GitHub expects and suggests.

This simply renames the existing code of conduct file from CONDUCT.md to CODE_OF_CONDUCT.md to conform to GitHub's preference.
2020-08-03 11:59:24 -04:00
Ville Skyttä
8bc71e9161 bash completion: avoid unintentional globbing 2020-05-26 22:31:38 +03:00
Ville Skyttä
a5a1c4d50d Make work in set -u (nounset) mode 2020-05-24 09:08:05 +03:00
Hiroshi SHIBATA
c879cb0f2f Merge pull request #1242 from scop/spelling
Spelling fix
2020-04-23 14:57:02 +09:00
Ville Skyttä
59004d77ed Spelling fix 2020-04-23 07:59:28 +03:00
Mislav Marohnić
c2cfbd1e8b Merge pull request #1227 from jasonkarns/agignore
Remove .agignore
2020-03-17 12:35:53 +01:00
Jason Karns
a17c5fb596 Remove agignore
Silver Searcher respects .gitignore, so having an .agignore file is
redundant. (Both patterns present in .agignore are already present in
.gitignore.)

It's also worth noting that silver searcher uses .agignore _in addition
to_ .gitignore, so removing this file will not cause ag to start
ignoring _additional_ patterns from .gitignore (it's already respecting
those patterns).
2020-03-16 17:02:27 -04:00
Mislav Marohnić
c6324ff45a Merge pull request #1220 from romanlevin/patch-1
Fix fish shell initialization
2020-02-17 23:50:04 +01:00
Roman Levin
74c2486a2c Fix fish instructions test 2020-02-17 21:46:25 +01:00
Roman Levin
ac5dce9014 Remove another fish psub usage 2020-02-17 21:38:46 +01:00
Roman Levin
19ae300eb8 Fix fish shell initialization
Since fish 3.10 at least, the current way of loading rbenv in `fish` is misbehaving, at least in some environments:

```
source: Error encountered while sourcing file '/var/folders/pj/jn249gcn7ddfrjzj2_9mxjhw0000gp/T//.psub.f0iJSWRByB':
source: No such file or directory
```

This changes the initialization to the method recommended by a `fish` developer here: https://github.com/fish-shell/fish-shell/issues/6613#issuecomment-586679958
2020-02-17 21:38:46 +01:00
Mislav Marohnić
e429cc0bd8 Use actions/checkout v2 2020-02-17 20:55:12 +01:00
Mislav Marohnić
d58cf6ec71 Run CI for pull requests from forks 2020-02-17 20:55:12 +01:00
Mislav Marohnić
143b2c9c02 Merge pull request #1216 from gibfahn/re-add_zsh_completions_and_remove_fish
Re-add zsh completion script and remove fish completion script
2020-01-29 11:51:15 +01:00
Gibson Fahnestock
f977248086 Re-add zsh completion script and remove fish completion script
Looks like the zsh completion script was removed by mistake.

Fixes: https://github.com/rbenv/rbenv/issues/1215
Refs: 569d464d36
2020-01-29 10:07:10 +00:00
Mislav Marohnić
569d464d36 Remove fish completion script
fish ships with a much more capable rbenv completion script since fish 2.0.

Fixes #1212
2020-01-28 17:47:59 +01:00
Mislav Marohnić
7795476af1 Merge pull request #1203 from jf/fix_misleading_set_by_message_for_system_ruby
libexec/rbenv-version: get rid of misleading "set by $(rbenv-version-origin)" message when system ruby is in use
2020-01-16 19:47:52 +01:00
Jeffrey 'jf' Lim
137e705db7 Fix (revert) test/version-origin.bats 2020-01-16 23:24:42 +08:00
Jeffrey 'jf' Lim
302797ba41 libexec/rbenv-version{,-origin}: move "missing rbenv-version-file detection" logic as per @mislav 2020-01-16 23:15:09 +08:00
Jeffrey 'jf' Lim
40db754168 Fix tests for #1203 2020-01-08 16:41:14 +08:00
Jeffrey 'jf' Lim
5c3268c9af libexec/rbenv-version{,-origin}: fix earlier commit to allow for RBENV_VERSION env var 2020-01-08 16:40:48 +08:00
Jeffrey 'jf' Lim
dd86f543fc libexec/rbenv-version: get rid of misleading "set by $(rbenv-version-origin)" message when system ruby is in use 2020-01-08 15:54:33 +08:00
Mislav Marohnić
c46a970595 Merge pull request #1196 from rbenv/ci-actions
Add CI via Actions
2019-10-24 00:37:19 +02:00
Mislav Marohnić
8bb5b1607e Bump Homebrew formula on tagged release 2019-10-24 00:24:37 +02:00
Mislav Marohnić
cc9726c641 Delete .travis.yml 2019-10-24 00:21:38 +02:00
Mislav Marohnić
a574a74042 Add CI via Actions 2019-10-24 00:18:28 +02:00
Mislav Marohnić
0c3967aa32 Merge branch 'fix/rbenv-help-type-broken-pipe-upstream' 2019-10-23 14:51:15 +02:00
Mislav Marohnić
af454a32dc Silence errors when piping type | head -1 2019-10-23 12:12:38 +02:00
Hongli Lai
d38d18ec25 rbenv help: fix 'type: write error: Broken pipe'
Sometimes the command fails with a 'type: write error: Broken pipe'.
This is because 'head -1' only reads the first line, then exits.
If 'type' writes the second line after 'head -1' has already exited,
then the aforementioned error is triggered.

We fix this by buffering the entire output of 'type' before
invoking 'head -1'.
2019-10-23 08:29:03 +02:00
SHIBATA Hiroshi
577f04653d Merge pull request #1191 from DestyNova/patch-1
Show how to update the list of available Ruby versions
2019-09-27 09:05:50 +09:00
Oisín
8ebf088360 Show how to update the list of available Ruby versions
It wasn't clear how to update the list of installable Ruby versions after installing rbenv from Git. This is a bit confusing for people who use rbenv to run third party Ruby apps rather than write their own and are less likely to know/care about the distinction between `rbenv` and `ruby-build`. I hadn't touched it for about 2 years and totally forgot that I'd need to manually update ruby-build.

Alternatively, it might be better to make ruby-build a git submodule.
2019-09-27 00:53:31 +01:00
Mislav Marohnić
4e923221ce Merge pull request #1156 from rbenv/no-dir-traversal
Disallow path segments and directory traversal in `.ruby-version` files
2019-04-04 16:21:05 +02:00
Mislav Marohnić
370c26a6c9 Disallow path segments and directory traversal in .ruby-version files
A malicious `.ruby-version` file in the current directory could inject
`../../../` into the version string and trigger execution of binaries
outside of `RBENV_ROOT/versions/`.

Fixes #977 OVE-20170303-0004
2019-04-03 12:58:25 +02:00
Mislav Marohnić
a3fa9b73b8 rbenv 1.1.2 2019-03-25 15:00:39 +01:00
Mislav Marohnić
483e7f9bdf Clarify the description of rbenv versions
Fixes #1148
2019-02-18 21:38:08 +01:00
Daniel Hahler
ae2e7a3f0b test/run: handle optional paths/args for bats
This allows to run a single test file more easily, although that could be
done by calling bats directly.
2018-09-19 08:24:48 +02:00
Mislav Marohnić
59785f6762 Merge pull request #1098 from blueyed/prefix-no-devnull
rbenv-prefix: do not silence rbenv-which for system version
2018-08-09 16:11:47 +02:00
Daniel Hahler
806f3f6ae2 rbenv-prefix: do not silence rbenv-which for system version
This suppressed any output when using RBENV_DEBUG=1 and does not really
hurt to have in the unlikely case that it should fail; you would get
two error messages now:

rbenv: ruby: command not found
rbenv: system version not found in PATH
2018-08-07 01:44:13 +02:00
Mislav Marohnić
1c772d5ff2 Merge pull request #1093 from blueyed/which
rbenv-which: change PATH only for the "command -v" lookup
2018-06-07 23:41:38 +02:00
Daniel Hahler
8103febc62 rbenv-which: change PATH only for the "command -v" lookup
This is not really necessary, because rbenv-which is used in a subshell
currently, but makes a difference if rbenv-which would be sourced.
2018-06-07 23:38:12 +02:00
jacob
8b18b962a3 make rbenv init more visible in the readme (#1092)
[ci skip]
2018-06-07 23:33:25 +02:00
Mislav Marohnić
199e598351 Remove ableist language 2018-06-05 16:49:13 +02:00
Mislav Marohnić
e55e3c05eb Merge pull request #1083 from AlexWayfer/patch-1
Update instructions for $PATH change in README
2018-06-05 01:45:30 +02:00
Mislav Marohnić
bc1b66250f Link to rbenv-installer
Fixes #1001
2018-06-05 01:22:16 +02:00
Alexander Popov
dfba9f7608 Update instructions for $PATH change in README
Describe for Fish shell in details, prevent issues like #195 and #459.

Reference: https://fishshell.com/docs/2.7/tutorial.html#tut_path
2018-05-30 15:11:09 +03:00
Mislav Marohnić
c8ba27fd07 Merge pull request #1069 from viclim/fix-issue-1065
Ignore empty `.ruby-version` files
2018-02-26 10:53:46 +01:00
Victor Lim
9daf81f16e Fix https://github.com/rbenv/rbenv/issues/1065
Command `rbenv version-name > .ruby-version` will create an empty `.ruby-version` file
before running `rbenv-version-file`. This causes `rbenv-version-file` to return empty
string which in turn causes `rbenv-version-name` to return `system`.

Ensure size of `.ruby-version` is non-zero as a workaround.
2018-02-26 16:49:37 +08:00
Mislav Marohnić
b943955dbf Merge pull request #981 from mhinz/shell-descriptive-error
Better error message for `rbenv shell`
2017-12-07 05:00:44 +01:00
Marco Hinz
643023d98f Add tests for shell integration 2017-12-07 02:32:35 +01:00
Marco Hinz
af53c790cc Better error message for rbenv shell
Shell integration is not enabled by default. This means that, from all the
commands from `rbenv commands`, only "shell" won't work right away.

Replace "no such command" with a more descriptive message that points to
`rbenv init` instead.
2017-12-07 02:32:34 +01:00
Mislav Marohnić
6aa70b6541 Merge pull request #1013 from blueyed/shellcheck
Fix some issues reported by shellcheck
2017-11-30 11:43:18 +01:00
Daniel Hahler
5f8a4c4d62 Fix some issues reported by shellcheck 2017-11-29 16:20:51 +01:00
Mislav Marohnić
eda952ab08 Merge branch 'cdpath-enable' 2017-11-29 15:53:41 +01:00
Mislav Marohnić
b80ea43e25 Quote directory name in variable assignment 2017-11-29 15:51:03 +01:00
Mislav Marohnić
c310bc5f83 Merge pull request #968 from maxnordlund/patch-1
Fix fish subcommand completion
2017-11-29 15:47:19 +01:00
Mislav Marohnić
eab68688dc Merge pull request #959 from zenspider/fix-dash-u
Fixed `rbenv init -` output to work w/ no args and bash's `set -u`.
2017-11-29 15:40:23 +01:00
Mislav Marohnić
5183e32887 Merge pull request #982 from MartinNowak/issue759
partly resolve #759
2017-11-29 15:37:22 +01:00
Mislav Marohnić
e2f469a7cd Merge pull request #1002 from blueyed/fix-which-tests-PATH
test/which.bats: do not export PATH
2017-11-29 15:25:03 +01:00
Mislav Marohnić
33a5c2495d Merge pull request #1003 from blueyed/version-file-skip-dirs
rbenv-version-file: ensure that the version file is a file
2017-11-29 15:23:58 +01:00
Mislav Marohnić
66b9f6fb2b Merge pull request #1024 from andyone/master
Fixed support for commas for all environment variables in configure script
2017-11-29 15:20:00 +01:00
Daniel Hahler
a9ca72ab8e test/which.bats: do not export PATH
Otherwise `sed` might not be found later in bats/libexec/bats-exec-test,
in case `/usr/bin` gets removed.
2017-11-20 04:22:05 +01:00
Ryan Davis
1a8b5e04a9 Fixed rbenv init - output to work w/ no args and bash's set -u. 2017-11-06 13:59:04 -08:00
Mislav Marohnić
2d7cefe782 Merge pull request #1034 from MinhThienDX/master
Fix URL fragment target
2017-09-04 18:57:27 +02:00
MinhThienDX
650c9d3452 Fix URL fragment target 2017-09-04 23:51:22 +07:00
Jeremy Daer
4ebd1bd12c Merge pull request #1009 from jeremy/homebrew-install-clarification
Clarify Homebrew/git install guidance
2017-08-23 14:47:56 -10:00
Anton Novojilov
dbaa8c83b6 Fixed support of build env vars for dynamic bash extension configure script 2017-08-07 13:12:37 +02:00
Advait Junnarkar
fb9130e85a Documentation unclear
Clarified how to finish installation by setting a Ruby version either globally or locally.
2017-07-05 18:15:57 +10:00
Mislav Marohnić
615f8443fe Merge pull request #1011 from kenaniah/patch-1
Properly escapes commas in c flags
2017-06-25 02:48:23 +02:00
Kenaniah Cerny
fc706daf60 properly escapes commas in cflags 2017-06-18 20:57:52 -07:00
Mislav Marohnić
6cd487db81 rbenv 1.1.1 2017-06-15 16:55:33 +02:00
Jeremy Daer
e3e99cc906 Clarify Homebrew/git install guidance
* Move Homebrew to the top, common case for new devs
* Note that `brew install rbenv` includes ruby-build by default
* Be clear that `rbenv init` instructions are needed for shell setup
* Be explicit about starting a new shell to pick up PATH/init changes
* Use rbenv-doctor to conclusively demonstrate correct setup
* Separate upgrade instructions for Homebrew vs Git installs

Related: https://github.com/rbenv/ruby-build/pull/1106
2017-06-14 09:02:50 -07:00
Daniel Hahler
95b1b05cbe rbenv-version-file: ensure that the version file is a file
Forwarded from https://github.com/pyenv/pyenv/pull/606.
2017-06-05 15:40:59 +02:00
Mislav Marohnić
755c820724 Merge pull request #986 from jeffkowalski/fix_init
Prefer 'set' over 'setenv' for fish shell
2017-05-17 00:34:20 +02:00
Mislav Marohnić
b4330a48b1 Merge pull request #999 from jacob-on-github/patch-1
Make homebrew installation instructions more clear
2017-05-17 00:12:52 +02:00
Jeff Kowalski
a81da8d864 Revert quoting change in previous commit; adjust test to match code
Revert back to original quoting style used before previous commit.
Adjust init.bats to reflect changes for successful tests.
2017-05-16 13:36:06 -07:00
jacob-on-github
4e27113494 Update README.md
I work on a team that has followed the Homebrew installations. More than once we've missed the `rbenv init` instruction and it has caused headaches down the road. This formatting makes it harder to miss.
2017-05-16 14:29:46 -05:00
Jeff Kowalski
be2e606fbd Prefer 'set' over 'setenv' for fish shell
The setenv function in fish shell has changed dramatically in
75600b6b53
It now conforms to the csh version, which takes at most two arguments.
In this init script, the form
    setenv PATH prepend_something $PATH
had been used, which had too many arguments.
Since setenv isn't a native command in fish, a suitable replacement is
to use the "set -gx" command, which can consume multiple arguments.
2017-04-06 23:55:48 -07:00
Tim Pope
9d93605e18 Don't unset CDPATH 2017-04-05 17:39:39 -04:00
Tim Pope
1f1e291385 Enforce absolute RBENV_DIR
This prevents CDPATH from becoming an issue.

Closes #866.
2017-04-05 16:54:03 -04:00
Martin Nowak
db39044ef6 partly resolve #759
- some versions of bash (e.g. 4.3.11) complain about clobbering
  /dev/null, use bash's explicit >| operator to ignore noclober
- not sure if the original #759 report has the same cause
- https://github.com/rbenv/rbenv/issues/759#issuecomment-289326891
2017-03-27 02:06:13 +02:00
Max Nordlund
fab5cf912f Fix pyenv -> rbenv typo 2017-02-10 09:31:13 +01:00
Max Nordlund
9f52b56aa8 Fix fish subcommand completion
This allows subcommand style plugins to properly autocomplete.
Existing commands are not affected. 

Example, say you have support for `rbenv foo bar --flag`, then
this allows the last `--flag` argument to be properly completed.
2017-02-10 09:12:30 +01:00
Mislav Marohnić
4f8925abe7 Merge pull request #958 from jasonkarns/rbenv-variable-namespace
Conforms OLD_RBENV_VERSION to RBENV_* convention
2016-12-20 14:34:32 +01:00
Jason Karns
8eb97549e1 Conforms OLD_RBENV_VERSION to RBENV_* convention
Keeping rbenv-controlled variables to RBENV_* "namespace" helps with
discoverability (and tools like rbenv-env) but also consistency and a
very minor degree of safety/isolation from env impact.
2016-12-19 17:21:45 -05:00
Mislav Marohnić
e60ad4a090 rbenv 1.1.0 2016-11-25 21:11:08 +01:00
Mislav Marohnić
6ced4e25de Merge pull request #873 from dmerand/patch-1
Fish shell "." is deprecated in favor of "source"
2016-11-25 20:32:54 +01:00
Mislav Marohnić
2207c27cb4 Merge branch 'shell-undo' 2016-11-25 20:26:24 +01:00
Mislav Marohnić
c4d97ad392 Finalize rbenv shell - implementation
This ensures that OLD_RBENV_VERSION is never exported. This makes the
implementation a little bit more complex, since more logic needs to be
pushed down into eval'd code.
2016-11-25 20:24:16 +01:00
Mislav Marohnić
1b751261ce Merge pull request #914 from yyuu/sh-help-stderr
Help message should not be written to stdout for `sh-` commands
2016-11-25 19:06:01 +01:00
Mislav Marohnić
c7dcaf1259 Merge pull request #924 from jlduran/add-freebsd-to-configure-c-extensions
src/configure: Add FreeBSD
2016-09-27 15:17:33 -04:00
Mislav Marohnić
d0779fc8fb Expand literal tilde in PATH
The literal tilde in a PATH entry (e.g. `~/.rbenv/shims`) doesn't seem
to be supported by system `which` utility, but *does* seem to be
supported by `command -v` (used in `rbenv-which`) and `type -p`.

Therefore, we must strip away `~/.rbenv/shims` from PATH when looking up
executables for system Ruby, lest we risk infinite loop. We do so by
substituting any occurence of `~` in PATH with the value of `HOME`.
2016-09-09 10:29:12 +02:00
Jose Luis Duran
99342d642f src/configure: Add FreeBSD 2016-08-08 17:24:07 -03:00
Mislav Marohnić
0c7224af95 Merge pull request #919 from yyuu/system-in-bin
Add a workaround system executable in `/bin`
2016-08-03 03:58:31 -09:00
Yamashita, Yuu
36138f4901 Rewrite with using here document syntax 2016-08-03 06:29:59 +00:00
Yamashita, Yuu
83e874a165 Add explicit shebang to executable for testing 2016-08-03 01:33:35 +00:00
Yamashita, Yuu
8eefa41a4d Remove useless touch line 2016-08-03 00:58:05 +00:00
Mislav Marohnić
57a902f36a Merge pull request #922 from jlduran/update-src-shobj-conf
Update `shobj-conf`
2016-08-02 19:04:10 +02:00
Jose Luis Duran
07fd1ae66b Update shobj-conf
Update the `shobj-conf` script imported from bash to support new OSs.
2016-08-02 11:36:37 -03:00
Yamashita, Yuu
a456528be8 Keep original ordering of PATH configuration 2016-08-02 00:21:28 +00:00
Yamashita, Yuu
6030ea51e4 Add a workaround for system executables in /bin 2016-08-01 00:32:50 +00:00
Yamashita, Yuu
2485257424 Add a test to confirm the prefix doesn't work fine with /bin/ruby 2016-08-01 00:31:11 +00:00
Yamashita, Yuu
26ac59fd1d Write help message to stdout 2016-07-04 00:56:08 +00:00
Yamashita, Yuu
7860ad5268 Help message should not be written to stdout for sh- commands (yyuu/pyenv#650) 2016-07-01 00:08:19 +00:00
Mislav Marohnić
9fdce5d069 Merge pull request #898 from mikelikesbikes/silence-stdout-when-cding
Properly unset CDPATH
2016-04-25 09:56:25 +02:00
Mike Busch
d246e20764 unset CDPATH if it's set by the user 2016-04-22 10:17:40 -05:00
Donald Merand
121159c089 Merge branch 'patch-1' of https://github.com/dmerand/rbenv into patch-1 2016-02-20 10:28:19 -05:00
Donald Merand
8b0b51a166 convert references to '.' to 'source' for fish shell 2016-02-20 10:27:39 -05:00
Sam Stephenson
29b4da7737 Adopt Contributor Covenant 1.4 2016-02-19 12:28:40 -06:00
Donald Merand
b81f0a2c42 Fish shell "." is deprecated in favor of "source"
Per [the fish documentation for "source"](file:///usr/local/Cellar/fish/2.2.0/share/doc/fish/commands.html#source) - ". (a single period) is an alias for the source command. The use of . is deprecated in favour of source, and . will be removed in a future version of fish."
2016-02-17 15:48:00 -05:00
Mislav Marohnić
ad7dfa63ab Merge pull request #870 from davidcelis/patch-1
Update `rbenv init` instructions
2016-02-15 10:23:29 +13:00
David Celis
35ca51fe88 Update rbenv init instructions
The README details `eval`ing `rbenv init -`, but for some shells (such as fish) there's a difference in what should be run. It turns out that `rbenv init` on its own will print correct instructions, so we should point users to running that command instead.
2016-02-14 09:08:00 -08:00
Mislav Marohnić
d6ab394efd Merge pull request #863 from ErikAGriffin/patch-1
Updated Mac OSX brew install command
2016-02-01 22:48:28 +11:00
Erik Griffn
d29ba1f80e Updated Mac OSX brew install command
It seems rbenv now comes with ruby-build.  I have not investigated fully, but the previously shown command: `brew install rbenv ruby-build` caused issues on my machine.  After uninstalling both and simply running `brew install rbenv` everything worked fine.
2016-02-01 11:17:56 +00:00
Aaron Patterson
6a912bf104 add support for rbenv shell -
`rbenv shell -` allows you to switch to the previously activated ruby
version.  Similar to `cd -` or `git checkout -`.

This tries to implement `rbenv shell -` as proposed in #854.  However,
adding support seemed to break the "shell change version" test.  I'm not
very good at Bash programming, can someone tell me what is wrong with
what I'm doing?  I'd like to add a bit more functionality to this, but
I'm really just cargo cult programming Bash.

Thank you!

fix tests
2016-01-12 15:32:59 -08:00
Mislav Marohnić
c38833179b Merge pull request #852 from jasonkarns/extract-hook-helper
Extract hook helper
2016-01-04 18:48:10 +01:00
Jason Karns
565798d617 Test IFS handling in version-name/version-origin hooks 2016-01-04 09:14:28 -05:00
Jason Karns
0f7a2cad8d Use create_hook helper
Use extracted create_hook helper in tests for:

- exec
- hooks
- rehash
- version-name
- version-origin
- which
2016-01-04 09:14:25 -05:00
Jason Karns
5ccba5d7cc Extract common create_hook helper 2016-01-04 09:14:04 -05:00
Jason Karns
2cc2ec160e Remove redundant test
Spaces in hook path is tested in test/hooks.bats
2016-01-04 09:13:58 -05:00
Mislav Marohnić
a95ccd09a2 Simplify fallback to global version file 2015-12-29 14:44:32 +01:00
Mislav Marohnić
e199a3d8f7 Merge pull request #850 from jasonkarns/remove-legacy-global-version-file
Remove support for legacy global version files
2015-12-29 14:40:37 +01:00
Mislav Marohnić
fec0f56d0b Merge pull request #849 from jasonkarns/remove-legacy-version-file-handling
Remove all handling/support of .rbenv-version files
2015-12-29 14:34:08 +01:00
Jason Karns
fe809ea90d Remove support for legacy global version files
`default` was made legacy back in 2011 with
5be66da9f4 (the command was renamed from
`rbenv-default` to `rbenv-global`, and so the global file was renamed
from `$RBENV_ROOT/default` to `$RBENV_ROOT/global` (the latter taking
precedence)

`global` was then made legacy about a month later in Sep 2011 when the
preferred filename was changed to `$RBENV_ROOT/version`.
2015-12-28 22:05:00 -05:00
Jason Karns
f880dc6d6f Remove support for legacy version file 2015-12-28 21:34:07 -05:00
Jason Karns
3c9674453f fix local --unset test 2015-12-28 21:33:50 -05:00
Mislav Marohnić
22f4980a21 🔥 deprecated ruby-local-exec
It was useless for a while now. I should have nuked it prior to the
1.0.0 release but I forgot :(
2015-12-25 00:26:46 +01:00
Mislav Marohnić
abbcde665c Fix ToC level
[ci skip]
2015-12-24 20:02:37 +01:00
Mislav Marohnić
c9c9415154 Update ToC 2015-12-24 20:01:36 +01:00
Mislav Marohnić
3997a394d9 rbenv 1.0.0 2015-12-24 19:12:47 +01:00
Mislav Marohnić
e0b85397c8 Point out that it's not necessary to sudo gem install
Closes #532
2015-12-24 19:12:47 +01:00
Mislav Marohnić
e554cd86c3 Strip leading : from RBENV_HOOK_PATH 2015-12-24 19:12:47 +01:00
Mislav Marohnić
38692f97fe vim ignores, the-silver-searcher ignores 2015-12-24 18:18:44 +01:00
Mislav Marohnić
7e5680a0d8 Add configure + make step to installation instructions
This compiles the `realpath` dynamic extension for bash which speeds up
symlink resolution. If the extension doesn't compile due to
cross-platform issues, rbenv will still work normally, although not as fast.
2015-12-24 18:04:17 +01:00
Mislav Marohnić
d51f6d4376 Merge branch 'detect-shell-from-script'
Closes #730
2015-12-24 13:24:54 +01:00
Mislav Marohnić
a9a9636d1e Tweak sanitizing shell name
Handles situation when the output is `/bin/shell- args...`. First strip
away the arguments, then the trailing dash.
2015-12-24 13:23:01 +01:00
Daniel Hahler
32030e2ed9 Fix shell version when invoked from a script
When invoked from a shell script, `$(rbenv init -)` did not get the
shell name correct.
It needs to look at the `args` value from `ps`.

Ref: https://github.com/yyuu/pyenv/issues/373
2015-12-24 13:21:22 +01:00
Mislav Marohnić
f9d8b551dc Add test for detecting shell when rbenv init is called from script
References #730
2015-12-24 13:20:49 +01:00
Mislav Marohnić
2c7960102c Simplify reference to realpath.dylib within rbenv-versions
The `../libexec` dance isn't necessary here. It was only necessary in
main `rbenv` command because that one might have been pointed to
directly via a symlink.
2015-12-24 03:54:32 +01:00
Mislav Marohnić
1a0be6f0ad Improve git --version git revision lookup
It doesn't try to chdir into RBENV_ROOT anymore because that might be
a location of an unrelated rbenv install that might have a different
version than the current one that is installed e.g. via a package
manager such as Homebrew.

Now just tries the repo where the source files (`libexec/*`) are
located, and if that isn't a valid rbenv repo, bail out early.
2015-12-24 03:52:33 +01:00
Mislav Marohnić
6481cbb172 Merge branch 'version-hooks'
Closes #739
2015-12-23 17:42:44 +01:00
Mislav Marohnić
6e30032278 Simplify version-name, version-origin hook tests
No need for helper function that's gonna be used just once.
2015-12-23 17:39:14 +01:00
Mislav Marohnić
4fde4ecbaf Ensure RBENV_VERSION_ORIGIN is not inherited from environment
It's only supposed to be set from `version-origin` hooks, but not
inherited from environment in case it was set.
2015-12-23 17:26:53 +01:00
Mislav Marohnić
40c1d27445 Merge remote-tracking branch 'origin/master' into version-hooks 2015-12-23 17:22:43 +01:00
Jason Karns
97f0499f43 add version-name/version-origin to hooks completion 2015-12-23 17:22:31 +01:00
Jason Karns
c3a5f91ed0 create hook: version-origin
Expose a `version-origin` hook.

It is invoked *before* the traditional `rbenv-version-file` lookup. Because `version-origin` is traditionally run immediately after `version-name`, then any plugin hooks that alter `version-name` would have done so. Thus, running `version-origin` prior to printing the origin gives those plugins a chance to alter the `version-origin` to match.

If any of the hooks set `$RBENV_VERSION_ORIGIN`, then it is used as the return value. Otherwise, the existing logic continues to return "environment variable" or "filename" as appropriate.

This change, in conjunction with the `version-name` hook, makes a clean seam by which plugins can inject their own ruby version setting logic. Using this seam, as opposed to altering `$RBENV_COMMAND_PATH` from the `which` hook, means that the version name and origin are set more reliably and so `version`, `version-name`, `version-origin` and `which` all work as expected. Indeed, even PS1 works now.
2015-12-23 17:22:31 +01:00
Jason Karns
258e4413b1 create hook: version-name
Expose a `version-name` hook.

It is invoked *after* the traditional `RBENV_VERSION` lookup. Which means hook scripts can interrogate `$RBENV_VERSION_FILE` and/or `$RBENV_VERSION` (or use the executables).

The hooks are then run, giving plugins a chance to alter `RBENV_VERSION`. Once the hooks have run, we now have (in `$RBENV_VERSION`) the actual version we want to use (or it's empty which defaults to `system` per normal). Lastly, the same logic remains for checking if the version exists, or trimming the `ruby-` prefix.

Prime example: the ruby-bundler-ruby-version plugin can select a ruby by using the `ruby` directive from the `Gemfile` if a local `.ruby-version` doesn't exist.
2015-12-23 17:22:30 +01:00
Mislav Marohnić
a62a75369e Merge branch 'rbenv-local-respects-ancestry' 2015-12-23 15:30:18 +01:00
Mislav Marohnić
ba072adcb9 Have rbenv local read version from parent directories as well
Fixes #807
2015-12-23 15:21:24 +01:00
Mislav Marohnić
ca25259900 Allow explicit target directory argument to rbenv-version-file
Can be used for `.ruby-version` file lookup in the ancestry of a
specific directory. In this mode of operation, global version files
aren't taken into consideration, and the command fails unless a local
version file was found.
2015-12-23 15:19:54 +01:00
Mislav Marohnić
90373d78b9 Add test for not including current directory in PATH search
Confirms #836
2015-12-14 11:59:01 +01:00
Mislav Marohnić
dc23ef10b6 Merge pull request #836 from eagletmt/fix-path
Remove leading `:`
2015-12-12 15:22:36 +01:00
Kohei Suzuki
3c7a13d81f Remove leading : 2015-12-12 15:28:34 +09:00
Mislav Marohnić
20755cfc15 Merge pull request #833 from chulkilee/fix-url
update urls to rbenv
2015-12-07 20:47:06 +01:00
Chulki Lee
df4c16ecb4 update urls to rbenv 2015-12-07 11:03:07 -08:00
Mislav Marohnić
f0e8bdcdaf Merge pull request #830 from ReadmeCritic/master
Update README URLs based on HTTP redirects
2015-11-25 19:49:54 +01:00
ReadmeCritic
f85c41b14f Update README URLs based on HTTP redirects 2015-11-25 10:08:28 -08:00
Mislav Marohnić
75a1dd25cd Merge pull request #828 from jasonkarns/formatting
indentation
2015-11-24 17:22:33 +01:00
Jason Karns
a1ef9efc80 use PWD var over pwd command 2015-11-23 09:13:31 -05:00
Jason Karns
87dd5fe2c0 indentation 2015-11-23 09:13:31 -05:00
Mislav Marohnić
5fb9c84e14 Merge pull request #822 from jasonkarns/completion
Add --help and tab completion to rbenv-versions
2015-11-20 18:37:54 +01:00
Mislav Marohnić
d138f5f5e4 Merge pull request #826 from jasonkarns/fail-helper
Extract `fail` helper function
2015-11-20 18:29:34 +01:00
Jason Karns
3ddedc021a Extract abort helper function
fail helper prints message to stderr and exits 1
(prefixes 'rbenv: ' if given a string arg)
2015-11-20 10:25:46 -05:00
Mislav Marohnić
a22adc77eb Merge pull request #827 from jasonkarns/fix-exec-test
Fix leftover .ruby-version file from exec.bats
2015-11-20 16:00:49 +01:00
Jason Karns
a3ff3adc39 create local .ruby-version file in test dir
This new test was creating an (intentionally invalid) .ruby-version file
in current working directory; typically the rbenv project dir.
Immediately after test runs, I had a leftover .ruby-version file.

The version-file tests create and cd into the RBENV_TEST_DIR as part of
setup(). I'm using the same directory for this test fix, but am only
using it for this particular test. None of the other exec tests seem to
need to be in a temp test dir, so no use putting it in setup().
2015-11-20 09:51:44 -05:00
Jason Karns
2dcb9d0611 completions for rbenv-init 2015-11-20 09:20:01 -05:00
Jason Karns
a6cb4b6317 consistent completions for rbenv-help 2015-11-20 09:15:06 -05:00
Jason Karns
2f917312f1 completions for rbenv-completions 2015-11-20 09:12:53 -05:00
Jason Karns
d1f8081d1c completions for rbenv-versions 2015-11-20 09:12:47 -05:00
Mislav Marohnić
63671a1479 Merge pull request #824 from jasonkarns/help-completion
Handle --help flag for subcommands
2015-11-20 14:28:39 +01:00
Jason Karns
d7ca2aba2a add --help to subcommand completions
ensure subcommand exists, then include --help in its completion output
2015-11-19 12:05:19 -05:00
Jason Karns
2c4dd63f77 handle --help for subcommands
If subcommand is provided (and exists) and its first arg is -h/--help,
go ahead and intercept the call; redirecting to rbenv-help <subcommand>

This means subcommands and plugins need not handle --help flag
themselves
2015-11-19 12:05:18 -05:00
Jason Karns
06e4f1b682 explicit --version flag
Without it, it falls back to `--version` being executed as a subcommand,
which works but isn't obvious
2015-11-19 11:14:59 -05:00
Mislav Marohnić
825de5d2e3 Fix argument handling in main rbenv command
- Explicitly asking for help with `-h` or `--help` exits with 0 status
  and displays help on stdout.

- Not providing any arguments to rbenv results in failure status and
  displays version and help on stderr.
2015-11-19 01:52:48 +01:00
Mislav Marohnić
8f87f43e22 Fix broken version-dependent test
Broken in dcca61c0bc
2015-11-14 12:21:16 +00:00
Mislav Marohnić
c30e096a54 Merge branch 'which-fixes' 2015-11-14 10:42:41 +00:00
Mislav Marohnić
3405c4d03c Fix error message when command is not found for "system" version
If `foo` didn't exist and `RBENV_VERSION=system rbenv which foo` was
called, the error message used to be misleading:

    rbenv: version `system' is not installed

Instead, have the error message simply say that the command was not found.

Fixes #770
2015-11-13 23:10:09 -05:00
Mislav Marohnić
09b18cf6f5 Add test for version-origin when version not found in rbenv-exec 2015-11-13 23:09:12 -05:00
Mislav Marohnić
fcedf169fb Merge pull request #819 from blueyed/fix-path_without
tests: fix path_without to handle /bin properly
2015-11-13 18:01:53 -05:00
Mislav Marohnić
14655a43c8 Merge pull request #821 from jasonkarns/help-completion
add completion block for rbenv-help
2015-11-13 17:37:09 -05:00
Jason Karns
8c3cab61c7 add completion block for rbenv-help 2015-11-13 15:06:29 -05:00
Daniel Hahler
6296bf3f8b tests: fix path_without to handle /bin properly
I was seeing /bin being left.  This patch fixes it by anchoring the search
pattern with ':' on both sides.
2015-11-12 21:20:00 +01:00
Mislav Marohnić
c18a3f9042 Merge pull request #814 from m-o-e/never-use-hardlinks
Never use hardlinks. Never.
2015-10-29 17:25:26 +01:00
moe
f6c1e5220a Never use hardlinks. Never. 2015-10-28 21:35:39 +01:00
Mislav Marohnić
d740406daf Merge pull request #812 from sstephenson/skip-aliases
Add `rbenv versions --skip-aliases` option
2015-10-27 21:11:24 +01:00
Mislav Marohnić
7026e529c7 Fix realpath fallback in rbenv hooks
The symlinks weren't correctly resolved if they were pointing to a
single path component, such as `ln -s foo bar`.
2015-10-27 21:05:10 +01:00
Mislav Marohnić
e80886e9be Add rbenv versions --skip-aliases option
Useful in combination with `--bare` to list just the unique version
numbers without the extra directory entries that are symlinks to other
version numbers in the same directory.
2015-10-27 21:05:10 +01:00
Mislav Marohnić
6e02b944f7 Use $BASH_SOURCE instead of $0
BASH_SOURCE might be more reliable.
2015-10-27 20:55:23 +01:00
Mislav Marohnić
bb129a782b Merge branch 'bundler-hook-recursion'
Closes #809, references #806
2015-10-27 10:54:13 +01:00
Roman Sandler
d508822f9a Make sure the alias statement only executes if there is not already an alias in place 2015-10-27 10:53:51 +01:00
Mislav Marohnić
6913fee89a If there is .bashrc but no .bash_profile, recommend the former
This is for Linux desktop platforms that have Terminal application
configured to start shells in interactive but not login mode. Creating a
`~/.bash_profile` would also cause `~/.profile` to not run, which might
be a problem on Ubuntu which ships with a default `~/.profile`.
2015-10-26 15:45:52 +01:00
Mislav Marohnić
074161f9c1 Merge pull request #806 from sstephenson/bundle-rehash
Avoid running `rbenv rehash` multiple times during `bundle install`
2015-10-25 18:36:20 +01:00
Mislav Marohnić
2b0f16757a Only rehash if bundle install actually created new executables
This avoids running `rbenv rehash` after installing libraries that don't
have executables, or after a no-op `bundle install` that didn't install
anything.
2015-10-25 18:31:50 +01:00
Mislav Marohnić
7b289bcee6 Avoid running rbenv rehash multiple times during bundle install
This is an attempt to work around the fact that Rubygems post_install
hooks may happen multiple times per single `bundle install` and ideally
we want `rbenv rehash` to run only once if new gems have been installed.
However, due to Bundler parallelism using `fork` on platforms that
support it, it's impossible for the child processes to communicate with
the master process to signal it to run `rbenv rehash` in the end.

This hooks into Bundler `install` command and runs `rbenv rehash` after
all gems have finished installing, but only if the install location was
system gems location and not a custom path (such as per-project
`vendor/bundle`).

This is limited because we can't tell whether any gems have been
installed at all, let alone do those gems have executables. However it's
better than having multiple `rbenv rehash` being run in parallel and
outputting confusing error messages as a result.
2015-10-25 17:47:01 +01:00
Mislav Marohnić
8dcd715ede Merge branch 'edge-version' 2015-10-25 17:01:04 +01:00
Mislav Marohnić
dcca61c0bc Improve rbenv --version git checkout discovery
When `rbenv --version` is called, this now happens:

1. It changes into the directory where `libexec/rbenv--version` resides
   and checks if it's a checkout of the rbenv repo (as opposed to
   Homebrew checkout or something else). Then it reads the git revision.

2. If that failed, change to `$RBENV_ROOT` directory and repeat step 1.
2015-10-25 16:54:38 +01:00
Mislav Marohnić
0f44c57d08 Fix eval'ing multiline sh-* command output with bash 2015-10-12 01:33:17 +02:00
Mislav Marohnić
efb187f26f Merge pull request #663 from kevinburke/use-command
Use `command` to run rbenv rehash
2015-10-11 04:04:46 +02:00
Mislav Marohnić
c101052a7f Fix eval'ing multiline sh-* command output with fish 2015-10-10 21:48:40 +02:00
Mislav Marohnić
51a1ee06e4 Merge commit '5c1094a' from #529
Closes #529
2015-10-10 19:17:18 +02:00
Mislav Marohnić
8a0555f8ef Init RBENV_TEST_DIR properly and only once during test setup 2015-10-10 19:02:11 +02:00
Mislav Marohnić
55f692ba9c Merge commit 'refs/pull/562/head' of https://github.com/sstephenson/rbenv 2015-10-10 18:42:36 +02:00
Mislav Marohnić
3a265c1af9 Unset XDG_CONFIG_HOME and related variables during tests
If set by the user's environment, `git config --global` writes will go
to that destination instead of temporary $HOME. We definitely don't want
that.

Fixes #742
2015-10-10 18:39:23 +02:00
Mislav Marohnić
c43928a8e4 Merge pull request #731 from blueyed/init-no-basename-for-shell
rbenv-init: do not use basename for $shell
2015-10-10 18:33:52 +02:00
Mislav Marohnić
c6cf4e18b8 Merge pull request #682 from evaryont/patch-1
Include gems dir in .gitignore
2015-10-10 17:22:55 +02:00
Mislav Marohnić
9e664b5d27 Suggest that rbenv should be loaded at end of shell rc file
Closes #725
2015-09-12 15:27:32 -07:00
Mislav Marohnić
3b6faa8531 Merge pull request #756 from blueyed/version-origin-with-non-installed
Display version origin with non-installed versions
2015-07-17 11:33:56 -07:00
Daniel Hahler
e3982fae38 Display version origin with non-installed versions
This is useful as an indicator where it is coming from.
2015-07-17 17:10:33 +02:00
Mislav Marohnić
83ac0fbd94 Merge pull request #747 from sstephenson/uninstall-instructions
Provide uninstall instructions in the README
2015-06-10 00:22:47 +02:00
Mislav Marohnić
46fbc5414a Provide uninstall instructions in the README 2015-06-09 23:31:01 +02:00
Mislav Marohnić
43b28caa94 Fix discovering .ruby-version files in root directory
It's not that this is a preferred way to set a global version (one
should use `rbenv global <version>` instead), but this fixes the
function purely for correctness: all parent directories should be
scanned, even the root directory.

Fixes #745
2015-06-09 17:24:15 +02:00
Daniel Hahler
4ea7d0849b rbenv-init: do not use basename for $shell
This can be done using bash directly.
2015-05-10 16:17:35 +02:00
Mislav Marohnić
5b9e4f0584 Merge pull request #722 from blueyed/fix-test-for-fish-issue-369
Fix test for adding shims in fish
2015-04-20 11:51:51 +02:00
Daniel Hahler
06c1959e78 Fix test for adding shims in fish
Commit e2173df4 (for issue #369) did not handle the fish test properly.

This renames it and fixes the assertion.
2015-04-19 23:53:19 +02:00
Kevin Burke
0cd078bae6 Merge branch 'master' into use-command 2015-03-31 18:57:44 -07:00
Mislav Marohnić
7ad01b2b48 Document rbenv environment variables
Closes #699, fixes #666 [ci skip]
2015-03-13 01:14:24 -07:00
Mislav Marohnić
8c6b764a4c Merge pull request #706 from mhw/realpath-configure-fix
Fix pattern replacement to allow flags with commas.
2015-03-12 22:18:23 -07:00
Mark H. Wilkinson
050f750563 Fix pattern replacement to allow flags with commas. 2015-03-11 13:14:52 +00:00
No GUI
55341f4436 Include gems dir in .gitignore
Since communal-gems is maintainer-approved, thought it would be useful to include the directory it uses in the ignore list.

(This also helps me, since I install rbenv as submodule and without this entry, the submodule is perpetually marked dirty.)
2015-01-20 13:21:22 -07:00
Kevin Burke
c9a96c9f79 Use command to run rbenv rehash
In the event that `eval "$(rbenv init -)"` is called from a function named
rbenv (which I do to get rbenv to load lazily in my shell), evaluating the
phrase `rbenv rehash` will cause the outer function to run again (causing an
infinite loop).

This change makes it clear you want the command named rbenv and not a function
which may exist in the environment.
2014-11-28 21:16:14 -08:00
Daniel Hahler
024bee1a6f Use mktemp -d for RBENV_TEST_DIR
This prevents the tests from removing an existing directory.

Fixes #561 (https://github.com/sstephenson/rbenv/issues/561)
2014-03-13 20:42:34 +01:00
kou1okada
5c1094adb9 Response enhancement for in the case of the working directory under the UNC path.
finding_local_version_file is extremely slow, when working directory is under the UNC path.
Because //host/.rbenv-version and //.rbenv-version do not exist, but testing them is so slow.
It's the reason to make a serious delay of the response, when the Ruby runs with a current working directory under the UNC path under Cygwin environment.

A response of before applying this patch.
//somehost/somedir $ time ruby -e "exit"

real    0m13.922s
user    0m0.168s
sys     0m0.287s

A response of after applying this patch.
//somehost/somedir $ time ruby -e "exit"

real    0m0.721s
user    0m0.153s
sys     0m0.319s
2014-01-09 15:31:29 +09:00
67 changed files with 1778 additions and 1601 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
/share/man/man[1-8]/*.[1-8] linguist-generated

6
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'

17
.github/workflows/ci.yml vendored Normal file
View 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
View 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
View 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.2
if: "!contains(github.ref, '-')" # skip prereleases
with:
formula-name: rbenv
env:
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}

1
.gitignore vendored
View File

@@ -7,3 +7,4 @@
/libexec/*.dylib /libexec/*.dylib
/src/Makefile /src/Makefile
/src/*.o /src/*.o
/gems

View File

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

1
.vimrc Normal file
View File

@@ -0,0 +1 @@
set wildignore+=versions/*,cache/*

80
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,80 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting one of the project maintainers listed below. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Project Maintainers
* Sam Stephenson <<sstephenson@gmail.com>>
* Mislav Marohnić <<mislav.marohnic@gmail.com>>
* Erik Michaels-Ober <<sferik@gmail.com>>
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

4
Makefile Normal file
View File

@@ -0,0 +1,4 @@
release_version := $(shell GIT_CEILING_DIRECTORIES=$(PWD) bin/rbenv --version | cut -d' ' -f2)
share/man/man1/rbenv.1: share/man/man1/rbenv.1.adoc
asciidoctor -b manpage -a version=$(release_version:v%=%) $<

551
README.md
View File

@@ -1,290 +1,169 @@
# Groom your apps Ruby environment with rbenv. # Seamlessly manage your apps 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/sstephenson/rbenv/wiki/Understanding-binstubs)
you'll never again need to `cd` in a cron job or Chef recipe to
ensure you've selected the right runtime. The Ruby version
dependency lives in one place—your app—so upgrades and rollbacks are
atomic, even when you switch versions.
**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/sstephenson/rbenv-vars).
See more [plugins on the
wiki](https://github.com/sstephenson/rbenv/wiki/Plugins).
[**Why choose rbenv over
RVM?**](https://github.com/sstephenson/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)
* [Uninstalling Ruby Versions](#uninstalling-ruby-versions)
* [Command Reference](#command-reference)
* [rbenv local](#rbenv-local)
* [rbenv global](#rbenv-global)
* [rbenv shell](#rbenv-shell)
* [rbenv versions](#rbenv-versions)
* [rbenv version](#rbenv-version)
* [rbenv rehash](#rbenv-rehash)
* [rbenv which](#rbenv-which)
* [rbenv whence](#rbenv-whence)
* [Development](#development)
## 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`. #### Fedora
~~~ sh Fedora has an [official package](https://packages.fedoraproject.org/pkgs/rbenv/rbenv/) which you can install:
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
~~~
2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` ```sh
command-line utility. sudo dnf install rbenv
```
~~~ sh 2. Set up your shell to load rbenv.
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
~~~
**Ubuntu Desktop note**: Modify your `~/.bashrc` instead of `~/.bash_profile`. ```sh
rbenv init
```
**Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`. 3. Close your Terminal window and open a new one so your changes take effect.
3. Add `rbenv init` to your shell to enable shims and autocompletion. That's it! You are now ready to [install some Ruby versions](#installing-ruby-versions).
~~~ sh ### Basic Git Checkout
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
~~~
_Same as in previous step, use `~/.bashrc` on Ubuntu, or `~/.zshrc` for Zsh._ > [!NOTE]
> 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.
4. Restart your shell so that PATH changes take effect. (Opening a new This will get you going with the latest version of rbenv without needing a system-wide install.
terminal tab will usually do it.) Now check if rbenv was set up:
~~~ sh 1. Clone rbenv into `~/.rbenv`.
$ type rbenv
#=> "rbenv is a function"
~~~
5. _(Optional)_ Install [ruby-build][], which provides the ```sh
`rbenv install` command that simplifies the process of git clone https://github.com/rbenv/rbenv.git ~/.rbenv
[installing new Ruby versions](#installing-ruby-versions). ```
#### Upgrading 2. Set up your shell to load rbenv.
If you've installed rbenv manually using git, you can upgrade your ```sh
installation to the cutting-edge version at any time. ~/.rbenv/bin/rbenv init
```
~~~ sh If you are curious, see here to [understand what `init` does](#how-rbenv-hooks-into-your-shell).
$ cd ~/.rbenv
$ git pull
~~~
To use a specific release of rbenv, check out the corresponding tag: 3. Restart your shell so that these changes take effect. (Opening a new terminal tab will usually do it.)
~~~ sh #### Shell completions
$ cd ~/.rbenv
$ git fetch
$ git checkout v0.3.0
~~~
If you've [installed via Homebrew](#homebrew-on-mac-os-x), then upgrade 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.
via its `brew` command:
~~~ sh - The **bash** completion script for rbenv ships with the project and gets [loaded by the `rbenv init` mechanism](#how-rbenv-hooks-into-your-shell).
$ brew update
$ brew upgrade rbenv ruby-build
~~~
### Homebrew on Mac OS X - 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`:
As an alternative to installation via GitHub checkout, you can install ```sh
rbenv and [ruby-build][] using the [Homebrew](http://brew.sh) package # assuming that rbenv was installed to `~/.rbenv`
manager on Mac OS X: FPATH=~/.rbenv/completions:"$FPATH"
~~~ autoload -U compinit
$ brew update compinit
$ brew install rbenv ruby-build ```
~~~
Afterwards you'll still need to add `eval "$(rbenv init -)"` to your - The **fish** completion script for rbenv ships with the fish shell itself and is not maintained by the rbenv project.
profile as stated in the caveats. You'll only ever have to do this
once.
### How rbenv hooks into your shell ### Installing Ruby versions
Skip this section unless you must know what every line in your shell The `rbenv install` command does not ship with rbenv out-of-the-box, but is provided by the [ruby-build][] plugin.
profile is doing.
`rbenv init` is the only command that crosses the line of loading 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:
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 ```sh
function properly. You can do this by hand by prepending # list latest stable versions:
`~/.rbenv/shims` to your `$PATH`. rbenv install -l
2. Installs autocompletion. This is entirely optional but pretty # list all local versions:
useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that rbenv install -L
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
The `rbenv install` command doesn't ship with rbenv out of the box, but
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
# list all available 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
elsewhere on the filesystem. rbenv doesn't care; it will simply treat
any entry in the `versions/` directory as a separate Ruby version.
### Uninstalling Ruby Versions > [!NOTE]
> If the `rbenv install` command wasn't found, you can install ruby-build as a plugin:
> ```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
Select a Ruby version for your project using `rbenv local 3.1.2`, for example. Then, proceed to install gems as you normally would:
```sh
gem install bundler
```
> [!NOTE]
> 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.
Check the location where gems are being installed with `gem env`:
```sh
gem env home
# => ~/.rbenv/versions/<version>/lib/ruby/gems/...
```
#### 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.
@@ -292,70 +171,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.
## 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
Previous versions of rbenv stored local version specifications in a
file named `.rbenv-version`. For backwards compatibility, rbenv will
read a local version specified in an `.rbenv-version` file, but a
`.ruby-version` file in the same directory will take precedence.
### rbenv global
Sets the global version of Ruby to be used in all shells by writing
the version name to the `~/.rbenv/version` file. This version can be
overridden by 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
@@ -378,13 +201,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
@@ -396,26 +267,84 @@ 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
jruby-1.7.1 jruby-1.7.1
ree-1.8.7-2011.03 ree-1.8.7-2011.03
## Environment variables
You can affect how rbenv operates with the following settings:
name | default | description
-----|---------|------------
`RBENV_VERSION` | | Specifies the Ruby version to be used.<br>Also see [`rbenv shell`](#rbenv-shell)
`RBENV_ROOT` | `~/.rbenv` | Defines the directory under which Ruby versions and shims reside.<br>Also see `rbenv root`
`RBENV_DEBUG` | | Outputs debug information.<br>Also as: `rbenv --debug <subcommand>`
`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.
### How rbenv hooks into your shell
`rbenv init` is a helper command to hook rbenv into a shell. This helper is part of the recommended installation instructions, but optional, as an experienced user can set up the following tasks manually. The `rbenv init` command has two modes of operation:
1. `rbenv init`: made for humans, this command edits your shell initialization files on disk to add rbenv to shell startup. (Prior to rbenv 1.3.0, this mode only printed user instructions to the terminal, but did nothing else.)
2. `rbenv init -`: made for machines, this command outputs a shell script suitable to be eval'd by the user's shell.
When `rbenv init` is invoked from a bash shell, for example, it will add the following to the user's `~/.bashrc` or `~/.bash_profile`:
```sh
# Added by `rbenv init` on <DATE>
eval "$(rbenv init - --no-rehash bash)"
```
You may add this line to your shell initialization files manually if you want to avoid running `rbenv init` as part of the setup process. Here is what the eval'd script does:
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.
### 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/sstephenson/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
Please feel free to submit pull requests and file bugs on the [issue Please feel free to submit pull requests and file bugs on the [issue
tracker](https://github.com/sstephenson/rbenv/issues). tracker](https://github.com/rbenv/rbenv/issues).
[ruby-build]: https://github.com/sstephenson/ruby-build#readme [ruby-build]: https://github.com/rbenv/ruby-build#readme
[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

View File

@@ -1,23 +0,0 @@
#!/usr/bin/env bash
#
# `ruby-local-exec` is a drop-in replacement for the standard Ruby
# shebang line:
#
# #!/usr/bin/env ruby-local-exec
#
# Use it for scripts inside a project with an `.rbenv-version`
# file. When you run the scripts, they'll use the project-specified
# Ruby version, regardless of what directory they're run from. Useful
# for e.g. running project tasks in cron scripts without needing to
# `cd` into the project first.
set -e
export RBENV_DIR="${1%/*}"
[ -n "$RBENV_SILENCE_WARNINGS" ] || {
echo "rbenv: \`ruby-local-exec' is deprecated and will be removed in the next release."
echo " To upgrade: https://github.com/sstephenson/rbenv/wiki/ruby-local-exec"
echo
} >&2
exec ruby "$@"

13
completions/_rbenv Normal file
View 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
}

View File

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

View File

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

View File

@@ -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}")
}

View File

@@ -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,45 +7,19 @@ 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
if enable -f "${0%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then abort() {
abs_dirname() { { if [ "$#" -eq 0 ]; then cat -
local path="$(realpath "$1")" else echo "rbenv: $*"
echo "${path%/*}" fi
} } >&2
else
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 exit 1
fi
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
@@ -55,35 +28,65 @@ fi
export RBENV_ROOT export RBENV_ROOT
if [ -z "${RBENV_DIR}" ]; then if [ -z "${RBENV_DIR}" ]; then
RBENV_DIR="$(pwd)" RBENV_DIR="$PWD"
else else
cd "$RBENV_DIR" 2>/dev/null || { [[ $RBENV_DIR == /* ]] || RBENV_DIR="$PWD/$RBENV_DIR"
echo "rbenv: cannot change working directory to \`$RBENV_DIR'" cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'"
exit 1 RBENV_DIR="$PWD"
} >&2
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/etc/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${plugin_hook}" RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${plugin_hook}"
done done
RBENV_HOOK_PATH="${RBENV_HOOK_PATH#:}"
export RBENV_HOOK_PATH export RBENV_HOOK_PATH
shopt -u nullglob shopt -u nullglob
@@ -91,20 +94,36 @@ shopt -u nullglob
command="$1" command="$1"
case "$command" in case "$command" in
"" | "-h" | "--help" ) "" )
echo -e "$(rbenv---version)\n$(rbenv-help)" >&2 { rbenv---version
rbenv-help
} | abort
;; ;;
"-v" ) -v | --version )
exec rbenv---version exec rbenv---version
;; ;;
-h | --help )
exec rbenv-help
;;
* ) * )
command_path="$(command -v "rbenv-$command" || true)" command_path="$(type -P "rbenv-$command" || true)"
if [ -z "$command_path" ]; then if [ -z "$command_path" ]; then
echo "rbenv: no such command \`$command'" >&2 if [ "$command" == "shell" ]; then
exit 1 abort "shell integration not enabled. Run \`rbenv init' for instructions."
else
abort "no such command \`$command'"
fi
fi fi
shift 1 shift 1
exec "$command_path" "$@" if [ "$1" = --help ]; then
if [[ "$command" == "sh-"* ]]; then
echo "rbenv help \"$command\""
else
exec rbenv-help "$command"
fi
else
exec "$command_path" "$@"
fi
;; ;;
esac esac

View File

@@ -12,9 +12,10 @@
set -e set -e
[ -n "$RBENV_DEBUG" ] && set -x [ -n "$RBENV_DEBUG" ] && set -x
version="0.4.0" version="1.3.2"
git_revision=""
if cd "$RBENV_ROOT" 2>/dev/null; then if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
git_revision="$(git describe --tags HEAD 2>/dev/null || true)" git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}" git_revision="${git_revision#v}"
fi fi

View File

@@ -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
@@ -12,32 +18,33 @@ if [ "$1" = "--complete" ]; then
exit exit
fi fi
exclude_shell=
command_prefix="rbenv-"
if [ "$1" = "--sh" ]; then if [ "$1" = "--sh" ]; then
sh=1 command_prefix="rbenv-sh-"
shift shift
elif [ "$1" = "--no-sh" ]; then elif [ "$1" = "--no-sh" ]; then
nosh=1 exclude_shell=1
shift shift
fi fi
IFS=: paths=($PATH)
shopt -s nullglob shopt -s nullglob
{ for path in "${paths[@]}"; do {
for command in "${path}/rbenv-"*; do PATH_remain="$PATH"
command="${command##*rbenv-}" # traverse PATH to find "rbenv-" prefixed commands
if [ -n "$sh" ]; then while true; do
if [ ${command:0:3} = "sh-" ]; then path="${PATH_remain%%:*}"
echo ${command##sh-} if [ -n "$path" ]; then
for rbenv_command in "${path}/${command_prefix}"*; do
rbenv_command="${rbenv_command##*rbenv-}"
if [[ -z $exclude_shell || $rbenv_command != sh-* ]]; then
echo "${rbenv_command##sh-}"
fi fi
elif [ -n "$nosh" ]; then done
if [ ${command:0:3} != "sh-" ]; then fi
echo ${command##sh-} [[ $PATH_remain == *:* ]] || break
fi PATH_remain="${PATH_remain#*:}"
else
echo ${command##sh-}
fi
done
done done
} | sort | uniq } | sort | uniq

View File

@@ -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
@@ -10,7 +10,16 @@ if [ -z "$COMMAND" ]; then
exit 1 exit 1
fi fi
COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")" # Provide rbenv completions
if [ "$COMMAND" = "--complete" ]; then
exec rbenv-commands
fi
COMMAND_PATH="$(type -P "rbenv-$COMMAND" "rbenv-sh-$COMMAND" | head -n1)"
# --help is provided automatically
echo --help
if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then
shift shift
exec "$COMMAND_PATH" --complete "$@" exec "$COMMAND_PATH" --complete "$@"

View File

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

View File

@@ -27,8 +27,5 @@ RBENV_VERSION_FILE="${RBENV_ROOT}/version"
if [ -n "$RBENV_VERSION" ]; then if [ -n "$RBENV_VERSION" ]; then
rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION"
else else
rbenv-version-file-read "$RBENV_VERSION_FILE" || rbenv-version-file-read "$RBENV_VERSION_FILE" || echo system
rbenv-version-file-read "${RBENV_ROOT}/global" ||
rbenv-version-file-read "${RBENV_ROOT}/default" ||
echo system
fi fi

View File

@@ -15,9 +15,15 @@
set -e set -e
[ -n "$RBENV_DEBUG" ] && set -x [ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
echo --usage
exec rbenv-commands
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() {
@@ -36,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
@@ -80,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
@@ -108,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
@@ -129,9 +144,41 @@ 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=()
shopt -s nullglob
PATH_remain="$PATH"
# traverse PATH to find "rbenv-" prefixed commands
while true; do
path="${PATH_remain%%:*}"
if [ -n "$path" ]; then
for rbenv_command in "${path}/rbenv-"*; do
command_name="${rbenv_command##*/}"
command_name="${command_name#rbenv-}"
command_name="${command_name#sh-}"
[[ $command_name == "${command_prefix}"* ]] || continue
[[ " ${seen[*]} " != *" ${command_name} "* ]] || continue
seen+=("$command_name")
summary=""
eval "$(extract_initial_comment_block < "$rbenv_command" | collect_documentation)"
[ -n "$summary" ] || continue
printf "%s:%s\n" "$command_name" "$summary"
done
fi
[[ $PATH_remain == *:* ]] || break
PATH_remain="${PATH_remain#*:}"
done
exit 0
fi
unset usage unset usage
if [ "$1" = "--usage" ]; then if [ "$1" = "--usage" ]; then
usage="1" usage="1"
@@ -139,14 +186,20 @@ 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/sstephenson/rbenv#readme" echo "For full documentation, see: https://github.com/rbenv/rbenv#readme"
else else
command="$1" command="$1"
if [ -n "$(command_path "$command")" ]; then if [ -n "$(command_path "$command")" ]; then

View File

@@ -9,6 +9,8 @@ set -e
if [ "$1" = "--complete" ]; then if [ "$1" = "--complete" ]; then
echo exec echo exec
echo rehash echo rehash
echo version-name
echo version-origin
echo which echo which
exit exit
fi fi
@@ -19,42 +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"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${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

View File

@@ -1,97 +1,178 @@
#!/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
print="" # Provide rbenv completions
no_rehash="" if [ "$1" = "--complete" ]; then
for args in "$@" echo -
do echo --no-rehash
if [ "$args" = "-" ]; then echo bash
print=1 echo fish
shift echo ksh
fi echo zsh
exit
if [ "$args" = "--no-rehash" ]; then
no_rehash=1
shift
fi
done
shell="$1"
if [ -z "$shell" ]; then
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}"
shell="${shell%% *}"
shell="$(basename "${shell:-$SHELL}")"
fi fi
root="${0%/*}/.." print=""
no_rehash=""
if [ -z "$print" ]; then shells=()
case "$shell" in while [ $# -gt 0 ]; do
bash ) case "$1" in
profile='~/.bash_profile' "-" )
print=1
;; ;;
zsh ) "--no-rehash" )
profile='~/.zshrc' no_rehash=1
;;
ksh )
profile='~/.profile'
;;
fish )
profile='~/.config/fish/config.fish'
;; ;;
* ) * )
profile='your profile' shells+=("$1")
;; ;;
esac esac
shift
done
{ echo "# Load rbenv automatically by adding" if [ "${#shells[@]}" -eq 0 ]; then
echo "# the following to ${profile}:" shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
echo shell="${shell%% *}"
shell="${shell##-}"
shell="${shell:-$SHELL}"
shell="${shell##*/}"
shells=("${shell%%-*}")
fi
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
display_path() {
if [ "${1/#$HOME\/}" != "$1" ]; then
# shellcheck disable=SC2088
printf '~/%s' "${1/#$HOME\/}"
else
printf '%s' "$1"
fi
}
rbenv_command=rbenv
if [ -z "$rbenv_in_path" ]; then
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 '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
@@ -101,14 +182,14 @@ function rbenv
switch "\$command" switch "\$command"
case ${commands[*]} case ${commands[*]}
eval (rbenv "sh-\$command" \$argv) 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
@@ -125,14 +206,14 @@ 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
case "\$command" in case "\$command" in
${commands[*]}) ${commands[*]})
eval "\`rbenv "sh-\$command" "\$@"\`";; eval "\$(rbenv "sh-\$command" "\$@")";;
*) *)
command rbenv "\$command" "\$@";; command rbenv "\$command" "\$@";;
esac esac

View File

@@ -15,10 +15,6 @@
# `RBENV_VERSION' environment variable takes precedence over local # `RBENV_VERSION' environment variable takes precedence over local
# and global versions. # and global versions.
# #
# For backwards compatibility, rbenv will also read version
# specifications from `.rbenv-version' files, but a `.ruby-version'
# file in the same directory takes precedence.
#
# <version> should be a string matching a Ruby version known to rbenv. # <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.
@@ -36,20 +32,14 @@ fi
RBENV_VERSION="$1" RBENV_VERSION="$1"
if [ "$RBENV_VERSION" = "--unset" ]; then if [ "$RBENV_VERSION" = "--unset" ]; then
rm -f .ruby-version .rbenv-version rm -f .ruby-version
elif [ -n "$RBENV_VERSION" ]; then elif [ -n "$RBENV_VERSION" ]; then
previous_file="$(RBENV_VERSION= rbenv-version-origin || true)"
rbenv-version-file-write .ruby-version "$RBENV_VERSION" rbenv-version-file-write .ruby-version "$RBENV_VERSION"
if [ "$previous_file" -ef .rbenv-version ]; then
rm -f .rbenv-version
{ echo "rbenv: removed existing \`.rbenv-version' file and migrated"
echo " local version specification to \`.ruby-version' file"
} >&2
fi
else else
rbenv-version-file-read .ruby-version || if version_file="$(rbenv-version-file "$PWD")"; then
rbenv-version-file-read .rbenv-version || rbenv-version-file-read "$version_file"
{ echo "rbenv: no local version configured for this directory" else
echo "rbenv: no local version configured for this directory" >&2
exit 1 exit 1
} >&2 fi
fi fi

View File

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

View File

@@ -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"
} }
@@ -81,10 +107,18 @@ remove_outdated_shims() {
# List basenames of executables for every Ruby version # List basenames of executables for every Ruby version
list_executable_names() { list_executable_names() {
local file local version file
for file in "$RBENV_ROOT"/versions/*/bin/*; do rbenv-versions --bare --skip-aliases | \
echo "${file##*/}" while read -r version; do
for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do
echo "${file##*/}"
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
@@ -94,23 +128,21 @@ 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" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$file" [ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
done done
} }
@@ -120,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
@@ -133,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

View File

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

View File

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

View File

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

View File

@@ -1,33 +1,34 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# 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
target_dir="$1"
find_local_version_file() { find_local_version_file() {
local root="$1" local root="$1"
while [ -n "$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"
exit return 0
elif [ -e "${root}/.rbenv-version" ]; then
echo "${root}/.rbenv-version"
exit
fi fi
[ -n "$root" ] || break
root="${root%/*}" root="${root%/*}"
done done
return 1
} }
find_local_version_file "$RBENV_DIR" if [ -n "$target_dir" ]; then
[ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD" find_local_version_file "$target_dir"
global_version_file="${RBENV_ROOT}/version"
if [ -e "$global_version_file" ]; then
echo "$global_version_file"
elif [ -e "${RBENV_ROOT}/global" ]; then
echo "${RBENV_ROOT}/global"
elif [ -e "${RBENV_ROOT}/default" ]; then
echo "${RBENV_ROOT}/default"
else else
echo "$global_version_file" find_local_version_file "$RBENV_DIR" || {
[ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
} || echo "${RBENV_ROOT}/version"
fi fi

View File

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

View File

@@ -8,6 +8,12 @@ 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
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-name)" || true
for script in "${scripts[@]}"; do
# shellcheck disable=SC1090
source "$script"
done
if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then
echo "system" echo "system"
exit exit
@@ -23,6 +29,6 @@ if version_exists "$RBENV_VERSION"; then
elif version_exists "${RBENV_VERSION#ruby-}"; then elif version_exists "${RBENV_VERSION#ruby-}"; then
echo "${RBENV_VERSION#ruby-}" echo "${RBENV_VERSION#ruby-}"
else else
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2 echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
exit 1 exit 1
fi fi

View File

@@ -3,7 +3,17 @@
set -e set -e
[ -n "$RBENV_DEBUG" ] && set -x [ -n "$RBENV_DEBUG" ] && set -x
if [ -n "$RBENV_VERSION" ]; then unset RBENV_VERSION_ORIGIN
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-origin)" || true
for script in "${scripts[@]}"; do
# shellcheck disable=SC1090
source "$script"
done
if [ -n "$RBENV_VERSION_ORIGIN" ]; then
echo "$RBENV_VERSION_ORIGIN"
elif [ -n "$RBENV_VERSION" ]; then
echo "RBENV_VERSION environment variable" echo "RBENV_VERSION environment variable"
else else
rbenv-version-file rbenv-version-file

View File

@@ -1,49 +1,83 @@
#!/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] # Usage: rbenv versions [--bare] [--skip-aliases]
# #
# Lists all Ruby versions found in `$RBENV_ROOT/versions/*'. # Lists all Ruby versions found in `$RBENV_ROOT/versions/*'.
set -e set -e
[ -n "$RBENV_DEBUG" ] && set -x [ -n "$RBENV_DEBUG" ] && set -x
if [ "$1" = "--bare" ]; then unset bare
hit_prefix="" unset skip_aliases
miss_prefix="" # Provide rbenv completions
current_version="" for arg; do
include_system="" case "$arg" in
else --complete )
hit_prefix="* " echo --bare
miss_prefix=" " echo --skip-aliases
current_version="$(rbenv-version-name || true)" exit ;;
include_system="1" --bare ) bare=1 ;;
fi --skip-aliases ) skip_aliases=1 ;;
* )
rbenv-help --usage versions >&2
exit 1
;;
esac
done
num_versions=0 canonicalize_dir() {
{ cd "$1" && pwd -P
print_version() { } 2>/dev/null || echo "$1"
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 "${RBENV_ROOT}/versions/"*; do local path
if [ -d "$path" ]; then local target
print_version "${path##*/}" shopt -s nullglob
fi for path in "$versions_dir"/*; do
done if [ -d "$path" ]; then
shopt -u nullglob if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
target="$(canonicalize_dir "$path")"
[ "${target%/*}" != "$versions_dir" ] || continue
fi
echo "${path##*/}"
fi
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"

View File

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

View File

@@ -18,12 +18,13 @@ 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:/:}"
done done
echo "${result%:}" result="${result%:}"
echo "${result#:}"
} }
RBENV_COMMAND="$1" RBENV_COMMAND="$1"
@@ -36,23 +37,26 @@ 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
if [ -x "$RBENV_COMMAND_PATH" ]; then if [ -x "$RBENV_COMMAND_PATH" ]; then
echo "$RBENV_COMMAND_PATH" echo "$RBENV_COMMAND_PATH"
elif ! [ -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then elif [ "$RBENV_VERSION" != "system" ] && [ ! -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2 echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
exit 1 exit 1
else else
echo "rbenv: $RBENV_COMMAND: command not found" >&2 echo "rbenv: $RBENV_COMMAND: command not found" >&2

View File

@@ -6,13 +6,40 @@ hook = lambda do |installer|
`rbenv rehash` `rbenv rehash`
end end
rescue rescue
warn "rbenv: error in gem-rehash (#{$!})" warn "rbenv: error in gem-rehash (#{$!.class.name}: #{$!.message})"
end end
end end
begin if defined?(Bundler::Installer) &&
Gem.post_install(&hook) Bundler::Installer.private_method_defined?(:install) &&
Gem.post_uninstall(&hook) !Bundler::Installer.private_method_defined?(:install_without_rbenv_rehash)
rescue Bundler::Installer.class_eval do
warn "rbenv: error installing gem-rehash hooks (#{$!})" private
alias install_without_rbenv_rehash install
def install(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(options)
if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before
`rbenv rehash`
end
result
end
end
else
begin
Gem.post_install(&hook)
Gem.post_uninstall(&hook)
rescue
warn "rbenv: error installing gem-rehash hooks (#{$!.class.name}: #{$!.message})"
end
end end

163
share/man/man1/rbenv.1 generated Normal file
View 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.2
.\" Language: English
.\"
.TH "RBENV" "1" "2023-11-08" "rbenv 1.3.2" "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ć

View 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

View File

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

View File

@@ -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
View File

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

View File

@@ -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
};

View File

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

View File

@@ -2,10 +2,13 @@
load test_helper load test_helper
export GIT_DIR="${RBENV_TEST_DIR}/.git"
setup() { setup() {
mkdir -p "$HOME" mkdir -p "$HOME"
git config --global user.name "Tester" git config --global user.name "Tester"
git config --global user.email "tester@test.local" git config --global user.email "tester@test.local"
cd "$RBENV_TEST_DIR"
} }
git_commit() { git_commit() {
@@ -16,31 +19,37 @@ git_commit() {
assert [ ! -e "$RBENV_ROOT" ] assert [ ! -e "$RBENV_ROOT" ]
run rbenv---version run rbenv---version
assert_success assert_success
[[ $output == "rbenv 0."* ]] [[ $output == "rbenv "?.?.? ]]
}
@test "doesn't read version from non-rbenv repo" {
git init
git remote add origin https://github.com/homebrew/homebrew.git
git_commit
git tag v1.0
run rbenv---version
assert_success
[[ $output == "rbenv "?.?.? ]]
} }
@test "reads version from git repo" { @test "reads version from git repo" {
mkdir -p "$RBENV_ROOT"
cd "$RBENV_ROOT"
git init git init
git remote add origin https://github.com/rbenv/rbenv.git
git_commit git_commit
git tag v0.4.1 git tag v0.4.1
git_commit git_commit
git_commit git_commit
cd "$RBENV_TEST_DIR"
run rbenv---version run rbenv---version
assert_success assert_success "rbenv 0.4.1-2-g$(git rev-parse --short HEAD)"
[[ $output == "rbenv 0.4.1-2-g"* ]]
} }
@test "prints default version if no tags in git repo" { @test "prints default version if no tags in git repo" {
mkdir -p "$RBENV_ROOT"
cd "$RBENV_ROOT"
git init git init
git remote add origin https://github.com/rbenv/rbenv.git
git_commit git_commit
cd "$RBENV_TEST_DIR"
run rbenv---version run rbenv---version
[[ $output == "rbenv 0."* ]] [[ $output == "rbenv "?.?.? ]]
} }

View File

@@ -13,7 +13,7 @@ create_command() {
create_command "rbenv-hello" "#!$BASH create_command "rbenv-hello" "#!$BASH
echo hello" echo hello"
run rbenv-completions hello run rbenv-completions hello
assert_success "" assert_success "--help"
} }
@test "command with completion support" { @test "command with completion support" {
@@ -25,7 +25,11 @@ else
exit 1 exit 1
fi" fi"
run rbenv-completions hello run rbenv-completions hello
assert_success "hello" assert_success
assert_output <<OUT
--help
hello
OUT
} }
@test "forwards extra arguments" { @test "forwards extra arguments" {
@@ -40,6 +44,7 @@ fi"
run rbenv-completions hello happy world run rbenv-completions hello happy world
assert_success assert_success
assert_output <<OUT assert_output <<OUT
--help
happy happy
world world
OUT OUT

View File

@@ -17,7 +17,15 @@ create_executable() {
@test "fails with invalid version" { @test "fails with invalid version" {
export RBENV_VERSION="2.0" export RBENV_VERSION="2.0"
run rbenv-exec ruby -v run rbenv-exec ruby -v
assert_failure "rbenv: version \`2.0' is not installed" assert_failure "rbenv: version \`2.0' is not installed (set by RBENV_VERSION environment variable)"
}
@test "fails with invalid version set from file" {
mkdir -p "$RBENV_TEST_DIR"
cd "$RBENV_TEST_DIR"
echo 1.9 > .ruby-version
run rbenv-exec rspec
assert_failure "rbenv: version \`1.9' is not installed (set by $PWD/.ruby-version)"
} }
@test "completes with names of executables" { @test "completes with names of executables" {
@@ -29,32 +37,20 @@ create_executable() {
run rbenv-completions exec run rbenv-completions exec
assert_success assert_success
assert_output <<OUT assert_output <<OUT
--help
rake rake
ruby ruby
OUT OUT
} }
@test "supports hook path with spaces" {
hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks"
mkdir -p "${hook_path}/exec"
echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash"
export RBENV_VERSION=system
RBENV_HOOK_PATH="$hook_path" run rbenv-exec env
assert_success
assert_line "HELLO=from hook"
}
@test "carries original IFS within hooks" { @test "carries original IFS within hooks" {
hook_path="${RBENV_TEST_DIR}/rbenv.d" create_hook exec hello.bash <<SH
mkdir -p "${hook_path}/exec"
cat > "${hook_path}/exec/hello.bash" <<SH
hellos=(\$(printf "hello\\tugly world\\nagain")) hellos=(\$(printf "hello\\tugly world\\nagain"))
echo HELLO="\$(printf ":%s" "\${hellos[@]}")" echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
SH SH
export RBENV_VERSION=system export RBENV_VERSION=system
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-exec env IFS=$' \t\n' run rbenv-exec env
assert_success assert_success
assert_line "HELLO=:hello:ugly:world:again" assert_line "HELLO=:hello:ugly:world:again"
} }
@@ -91,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

View File

@@ -3,7 +3,7 @@
load test_helper load test_helper
@test "default" { @test "default" {
run rbenv global run rbenv-global
assert_success assert_success
assert_output "system" assert_output "system"
} }
@@ -20,7 +20,7 @@ load test_helper
mkdir -p "$RBENV_ROOT/versions/1.2.3" mkdir -p "$RBENV_ROOT/versions/1.2.3"
run rbenv-global "1.2.3" run rbenv-global "1.2.3"
assert_success assert_success
run rbenv global run rbenv-global
assert_success "1.2.3" assert_success "1.2.3"
} }

View File

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

View File

@@ -2,11 +2,6 @@
load test_helper load test_helper
create_hook() {
mkdir -p "$1/$2"
touch "$1/$2/$3"
}
@test "prints usage help given no argument" { @test "prints usage help given no argument" {
run rbenv-hooks run rbenv-hooks
assert_failure "Usage: rbenv hooks <command>" assert_failure "Usage: rbenv hooks <command>"
@@ -15,11 +10,13 @@ create_hook() {
@test "prints list of hooks" { @test "prints list of hooks" {
path1="${RBENV_TEST_DIR}/rbenv.d" path1="${RBENV_TEST_DIR}/rbenv.d"
path2="${RBENV_TEST_DIR}/etc/rbenv_hooks" path2="${RBENV_TEST_DIR}/etc/rbenv_hooks"
create_hook "$path1" exec "hello.bash" RBENV_HOOK_PATH="$path1"
create_hook "$path1" exec "ahoy.bash" create_hook exec "hello.bash"
create_hook "$path1" exec "invalid.sh" create_hook exec "ahoy.bash"
create_hook "$path1" which "boom.bash" create_hook exec "invalid.sh"
create_hook "$path2" exec "bueno.bash" create_hook which "boom.bash"
RBENV_HOOK_PATH="$path2"
create_hook exec "bueno.bash"
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
assert_success assert_success
@@ -33,8 +30,10 @@ OUT
@test "supports hook paths with spaces" { @test "supports hook paths with spaces" {
path1="${RBENV_TEST_DIR}/my hooks/rbenv.d" path1="${RBENV_TEST_DIR}/my hooks/rbenv.d"
path2="${RBENV_TEST_DIR}/etc/rbenv hooks" path2="${RBENV_TEST_DIR}/etc/rbenv hooks"
create_hook "$path1" exec "hello.bash" RBENV_HOOK_PATH="$path1"
create_hook "$path2" exec "ahoy.bash" create_hook exec "hello.bash"
RBENV_HOOK_PATH="$path2"
create_hook exec "ahoy.bash"
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
assert_success assert_success
@@ -44,22 +43,28 @@ ${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash
OUT OUT
} }
@test "resolves relative paths" { @test "does not canonicalize paths" {
path="${RBENV_TEST_DIR}/rbenv.d" RBENV_HOOK_PATH="${RBENV_TEST_DIR}/rbenv.d"
create_hook "$path" 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"
touch "${HOME}/hola.bash" touch "${HOME}/hola.bash"
ln -s "../../home/hola.bash" "${path}/exec/hello.bash" ln -s "../../home/hola.bash" "${path}/exec/hello.bash"
touch "${path}/exec/bright.sh"
ln -s "bright.sh" "${path}/exec/world.bash"
RBENV_HOOK_PATH="$path" run rbenv-hooks exec RBENV_HOOK_PATH="$path" run rbenv-hooks exec
assert_success "${HOME}/hola.bash" assert_success
assert_output <<OUT
${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash
${RBENV_TEST_DIR}/rbenv.d/exec/world.bash
OUT
} }

90
test/init.bats Normal file → Executable file
View File

@@ -14,34 +14,102 @@ load test_helper
@test "auto rehash" { @test "auto rehash" {
run rbenv-init - run rbenv-init -
assert_success assert_success
assert_line "rbenv rehash 2>/dev/null" assert_line "command rbenv rehash 2>/dev/null"
} }
@test "setup shell completions" { @test "setup shell completions" {
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" {
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
SHELL=/bin/false run rbenv-init - SHELL=/bin/false run rbenv-init -
assert_success assert_success
assert_line "export RBENV_SHELL=bash" assert_line "export RBENV_SHELL=bash"
} }
@test "setup shell completions (fish)" { @test "detect parent shell from script" {
mkdir -p "$RBENV_TEST_DIR"
cd "$RBENV_TEST_DIR"
cat > myscript.sh <<OUT
#!/bin/sh
eval "\$(rbenv-init -)"
echo \$RBENV_SHELL
OUT
chmod +x myscript.sh
run ./myscript.sh
assert_success "sh"
}
@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" {
@@ -61,7 +129,7 @@ load test_helper
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" {
@@ -71,11 +139,11 @@ load test_helper
assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
} }
@test "doesn't add shims to PATH more than once (fish)" { @test "can add shims to PATH more than once (fish)" {
export PATH="${RBENV_ROOT}/shims:$PATH" export PATH="${RBENV_ROOT}/shims:$PATH"
run rbenv-init - fish run rbenv-init - fish
assert_success assert_success
refute_line '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" {

View File

@@ -19,24 +19,11 @@ setup() {
assert_success "1.2.3" assert_success "1.2.3"
} }
@test "supports legacy .rbenv-version file" { @test "discovers version file in parent directory" {
echo "1.2.3" > .rbenv-version
run rbenv-local
assert_success "1.2.3"
}
@test "local .ruby-version has precedence over .rbenv-version" {
echo "1.8" > .rbenv-version
echo "2.0" > .ruby-version
run rbenv-local
assert_success "2.0"
}
@test "ignores version in parent directory" {
echo "1.2.3" > .ruby-version echo "1.2.3" > .ruby-version
mkdir -p "subdir" && cd "subdir" mkdir -p "subdir" && cd "subdir"
run rbenv-local run rbenv-local
assert_failure assert_success "1.2.3"
} }
@test "ignores RBENV_DIR" { @test "ignores RBENV_DIR" {
@@ -64,40 +51,9 @@ setup() {
assert [ "$(cat .ruby-version)" = "1.2.3" ] assert [ "$(cat .ruby-version)" = "1.2.3" ]
} }
@test "renames .rbenv-version to .ruby-version" {
echo "1.8.7" > .rbenv-version
mkdir -p "${RBENV_ROOT}/versions/1.9.3"
run rbenv-local
assert_success "1.8.7"
run rbenv-local "1.9.3"
assert_success
assert_output <<OUT
rbenv: removed existing \`.rbenv-version' file and migrated
local version specification to \`.ruby-version' file
OUT
assert [ ! -e .rbenv-version ]
assert [ "$(cat .ruby-version)" = "1.9.3" ]
}
@test "doesn't rename .rbenv-version if changing the version failed" {
echo "1.8.7" > .rbenv-version
assert [ ! -e "${RBENV_ROOT}/versions/1.9.3" ]
run rbenv-local "1.9.3"
assert_failure "rbenv: version \`1.9.3' not installed"
assert [ ! -e .ruby-version ]
assert [ "$(cat .rbenv-version)" = "1.8.7" ]
}
@test "unsets local version" { @test "unsets local version" {
touch .ruby-version touch .ruby-version
run rbenv-local --unset run rbenv-local --unset
assert_success "" assert_success ""
assert [ ! -e .rbenv-version ] assert [ ! -e .ruby-version ]
}
@test "unsets alternate version file" {
touch .rbenv-version
run rbenv-local --unset
assert_success ""
assert [ ! -e .rbenv-version ]
} }

View File

@@ -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
} }

View File

@@ -4,8 +4,8 @@ load test_helper
@test "blank invocation" { @test "blank invocation" {
run rbenv run rbenv
assert_success assert_failure
assert [ "${lines[0]}" = "rbenv 0.4.0" ] assert_line 0 "$(rbenv---version)"
} }
@test "invalid command" { @test "invalid command" {
@@ -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 7 "${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
@@ -70,6 +76,7 @@ load test_helper
} }
@test "RBENV_HOOK_PATH includes rbenv built-in plugins" { @test "RBENV_HOOK_PATH includes rbenv built-in plugins" {
unset RBENV_HOOK_PATH
run rbenv echo "RBENV_HOOK_PATH" run rbenv echo "RBENV_HOOK_PATH"
assert_success ":${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/etc/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
} }

View File

@@ -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,16 +105,45 @@ 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" {
hook_path="${RBENV_TEST_DIR}/rbenv.d" create_hook rehash hello.bash <<SH
mkdir -p "${hook_path}/rehash"
cat > "${hook_path}/rehash/hello.bash" <<SH
hellos=(\$(printf "hello\\tugly world\\nagain")) hellos=(\$(printf "hello\\tugly world\\nagain"))
echo HELLO="\$(printf ":%s" "\${hellos[@]}")" echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
exit exit
SH SH
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-rehash IFS=$' \t\n' run rbenv-rehash
assert_success assert_success
assert_output "HELLO=:hello:ugly:world:again" assert_output "HELLO=:hello:ugly:world:again"
} }

View File

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

View File

@@ -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
} }

View File

@@ -1,20 +1,14 @@
unset RBENV_VERSION unset RBENV_VERSION
unset RBENV_DIR unset RBENV_DIR
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
RBENV_TEST_DIR="$(realpath "$BATS_TMPDIR")/rbenv"
else
if [ -n "$RBENV_NATIVE_EXT" ]; then
echo "rbenv: failed to load \`realpath' builtin" >&2
exit 1
fi
RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv"
fi
# guard against executing this block twice due to bats internals # guard against executing this block twice due to bats internals
if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then if [ -z "$RBENV_TEST_DIR" ]; then
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_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"
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
PATH="${RBENV_TEST_DIR}/bin:$PATH" PATH="${RBENV_TEST_DIR}/bin:$PATH"
@@ -22,6 +16,9 @@ if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
PATH="${RBENV_ROOT}/shims:$PATH" PATH="${RBENV_ROOT}/shims:$PATH"
export PATH export PATH
for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done
unset xdg_var
fi fi
teardown() { teardown() {
@@ -106,20 +103,29 @@ assert() {
# but in which system utils necessary for rbenv operation are still available. # but in which system utils necessary for rbenv operation are still available.
path_without() { 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
done done
path="${path/${found}:/${alt}:}" path="${path/:${found}:/:${alt}:}"
fi fi
done done
path="${path#:}"
echo "${path%:}" echo "${path%:}"
} }
create_hook() {
mkdir -p "${RBENV_HOOK_PATH}/$1"
touch "${RBENV_HOOK_PATH}/$1/$2"
if [ ! -t 0 ]; then
cat > "${RBENV_HOOK_PATH}/$1/$2"
fi
}

View File

@@ -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'"
}

View File

@@ -9,7 +9,13 @@ setup() {
create_file() { create_file() {
mkdir -p "$(dirname "$1")" mkdir -p "$(dirname "$1")"
touch "$1" echo "system" > "$1"
}
@test "detects global 'version' file" {
create_file "${RBENV_ROOT}/version"
run rbenv-version-file
assert_success "${RBENV_ROOT}/version"
} }
@test "prints global file if no version files exist" { @test "prints global file if no version files exist" {
@@ -19,45 +25,12 @@ create_file() {
assert_success "${RBENV_ROOT}/version" assert_success "${RBENV_ROOT}/version"
} }
@test "detects 'global' file" {
create_file "${RBENV_ROOT}/global"
run rbenv-version-file
assert_success "${RBENV_ROOT}/global"
}
@test "detects 'default' file" {
create_file "${RBENV_ROOT}/default"
run rbenv-version-file
assert_success "${RBENV_ROOT}/default"
}
@test "'version' has precedence over 'global' and 'default'" {
create_file "${RBENV_ROOT}/version"
create_file "${RBENV_ROOT}/global"
create_file "${RBENV_ROOT}/default"
run rbenv-version-file
assert_success "${RBENV_ROOT}/version"
}
@test "in current directory" { @test "in current directory" {
create_file ".ruby-version" create_file ".ruby-version"
run rbenv-version-file run rbenv-version-file
assert_success "${RBENV_TEST_DIR}/.ruby-version" assert_success "${RBENV_TEST_DIR}/.ruby-version"
} }
@test "legacy file in current directory" {
create_file ".rbenv-version"
run rbenv-version-file
assert_success "${RBENV_TEST_DIR}/.rbenv-version"
}
@test ".ruby-version has precedence over legacy file" {
create_file ".ruby-version"
create_file ".rbenv-version"
run rbenv-version-file
assert_success "${RBENV_TEST_DIR}/.ruby-version"
}
@test "in parent directory" { @test "in parent directory" {
create_file ".ruby-version" create_file ".ruby-version"
mkdir -p project mkdir -p project
@@ -74,14 +47,6 @@ create_file() {
assert_success "${RBENV_TEST_DIR}/project/.ruby-version" assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
} }
@test "legacy file has precedence if higher" {
create_file ".ruby-version"
create_file "project/.rbenv-version"
cd project
run rbenv-version-file
assert_success "${RBENV_TEST_DIR}/project/.rbenv-version"
}
@test "RBENV_DIR has precedence over PWD" { @test "RBENV_DIR has precedence over PWD" {
create_file "widget/.ruby-version" create_file "widget/.ruby-version"
create_file "project/.ruby-version" create_file "project/.ruby-version"
@@ -97,3 +62,14 @@ create_file() {
RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file
assert_success "${RBENV_TEST_DIR}/project/.ruby-version" assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
} }
@test "finds version file in target directory" {
create_file "project/.ruby-version"
run rbenv-version-file "${PWD}/project"
assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
}
@test "fails when no version file in target directory" {
run rbenv-version-file "$PWD"
assert_failure ""
}

View File

@@ -17,11 +17,32 @@ 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"
} }
@test "RBENV_VERSION can be overridden by hook" {
create_version "1.8.7"
create_version "1.9.3"
create_hook version-name test.bash <<<"RBENV_VERSION=1.9.3"
RBENV_VERSION=1.8.7 run rbenv-version-name
assert_success "1.9.3"
}
@test "carries original IFS within hooks" {
create_hook version-name hello.bash <<SH
hellos=(\$(printf "hello\\tugly world\\nagain"))
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
SH
export RBENV_VERSION=system
IFS=$' \t\n' run rbenv-version-name env
assert_success
assert_line "HELLO=:hello:ugly:world:again"
}
@test "RBENV_VERSION has precedence over local" { @test "RBENV_VERSION has precedence over local" {
create_version "1.8.7" create_version "1.8.7"
create_version "1.9.3" create_version "1.9.3"
@@ -49,7 +70,7 @@ setup() {
@test "missing version" { @test "missing version" {
RBENV_VERSION=1.2 run rbenv-version-name RBENV_VERSION=1.2 run rbenv-version-name
assert_failure "rbenv: version \`1.2' is not installed" assert_failure "rbenv: version \`1.2' is not installed (set by RBENV_VERSION environment variable)"
} }
@test "version with prefix in name" { @test "version with prefix in name" {

View File

@@ -26,13 +26,31 @@ 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"
} }
@test "detects alternate version file" { @test "reports from hook" {
touch .rbenv-version create_hook version-origin test.bash <<<"RBENV_VERSION_ORIGIN=plugin"
run rbenv-version-origin
assert_success "${PWD}/.rbenv-version" RBENV_VERSION=1 run rbenv-version-origin
assert_success "plugin"
}
@test "carries original IFS within hooks" {
create_hook version-origin hello.bash <<SH
hellos=(\$(printf "hello\\tugly world\\nagain"))
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
SH
export RBENV_VERSION=system
IFS=$' \t\n' run rbenv-version-origin env
assert_success
assert_line "HELLO=:hello:ugly:world:again"
}
@test "doesn't inherit RBENV_VERSION_ORIGIN from environment" {
RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin
assert_success "${RBENV_ROOT}/version"
} }

View File

@@ -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)"
}

View File

@@ -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
} }
@@ -139,3 +145,18 @@ OUT
1.8.7 1.8.7
OUT OUT
} }
@test "doesn't list symlink aliases when --skip-aliases" {
create_version "1.8.7"
ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8"
mkdir moo
ln -s "${PWD}/moo" "${RBENV_ROOT}/versions/1.9"
run rbenv-versions --bare --skip-aliases
assert_success
assert_output <<OUT
1.8.7
1.9
OUT
}

View File

@@ -56,24 +56,42 @@ create_executable() {
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
} }
@test "doesn't include current directory in PATH search" {
bats_require_minimum_version 1.5.0
mkdir -p "$RBENV_TEST_DIR"
cd "$RBENV_TEST_DIR"
touch kill-all-humans
chmod +x kill-all-humans
PATH="$(path_without "kill-all-humans")" RBENV_VERSION=system run -127 rbenv-which kill-all-humans
assert_failure "rbenv: kill-all-humans: command not found"
}
@test "version not installed" { @test "version not installed" {
create_executable "2.0" "rspec" create_executable "2.0" "rspec"
RBENV_VERSION=1.9 run rbenv-which rspec RBENV_VERSION=1.9 run rbenv-which rspec
assert_failure "rbenv: version \`1.9' is not installed" assert_failure "rbenv: version \`1.9' is not installed (set by RBENV_VERSION environment variable)"
} }
@test "no executable found" { @test "no executable found" {
bats_require_minimum_version 1.5.0
create_executable "1.8" "rspec" create_executable "1.8" "rspec"
RBENV_VERSION=1.8 run rbenv-which rake RBENV_VERSION=1.8 run -127 rbenv-which rake
assert_failure "rbenv: rake: command not found"
}
@test "no executable found for system version" {
bats_require_minimum_version 1.5.0
PATH="$(path_without "rake")" RBENV_VERSION=system run -127 rbenv-which rake
assert_failure "rbenv: rake: command not found" assert_failure "rbenv: rake: command not found"
} }
@test "executable found in other versions" { @test "executable found in other versions" {
bats_require_minimum_version 1.5.0
create_executable "1.8" "ruby" create_executable "1.8" "ruby"
create_executable "1.9" "rspec" create_executable "1.9" "rspec"
create_executable "2.0" "rspec" create_executable "2.0" "rspec"
RBENV_VERSION=1.8 run rbenv-which rspec RBENV_VERSION=1.8 run -127 rbenv-which rspec
assert_failure assert_failure
assert_output <<OUT assert_output <<OUT
rbenv: rspec: command not found rbenv: rspec: command not found
@@ -84,16 +102,37 @@ The \`rspec' command exists in these Ruby versions:
OUT OUT
} }
@test "executable not found in user gems" {
bats_require_minimum_version 1.5.0
create_executable "2.7.6" "ruby"
create_executable "${HOME}/.gem/ruby/2.7.0/bin" "rake"
GEM_HOME='' RBENV_VERSION=2.7.6 run -127 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" {
hook_path="${RBENV_TEST_DIR}/rbenv.d" create_hook which hello.bash <<SH
mkdir -p "${hook_path}/which"
cat > "${hook_path}/which/hello.bash" <<SH
hellos=(\$(printf "hello\\tugly world\\nagain")) hellos=(\$(printf "hello\\tugly world\\nagain"))
echo HELLO="\$(printf ":%s" "\${hellos[@]}")" echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
exit exit
SH SH
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' RBENV_VERSION=system run rbenv-which anything IFS=$' \t\n' RBENV_VERSION=system run rbenv-which anything
assert_success assert_success
assert_output "HELLO=:hello:ugly:world:again" assert_output "HELLO=:hello:ugly:world:again"
} }
@@ -106,6 +145,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"
} }