Commit graph

150 commits

Author SHA1 Message Date
Mikel Olasagasti Uranga e5c7eb3399 Skip BW01 and BW02 error messages during tests 2024-12-10 22:03:36 +01: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ć 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ć 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
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
Mislav Marohnić 592fe6a087
help: have --usage always print a usage line 2023-07-11 18:54:38 +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
Richie Thomas 85f304ef3b Prefer local over global version file 2022-10-15 11:11:48 -05:00
Mislav Marohnić 3e5347be1e
Make the usage syntax for arbitrary args consistent (#1447) 2022-10-09 14:49:15 +02:00
Mislav Marohnić 410e05bf8c
Revert support for user-installed gems (#1443) 2022-10-07 12:56:54 +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ć 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ć 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
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
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
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ć 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
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
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
Ville Skyttä a5a1c4d50d Make work in set -u (nounset) mode 2020-05-24 09:08:05 +03:00
Ville Skyttä 59004d77ed Spelling fix 2020-04-23 07:59:28 +03:00
Roman Levin 74c2486a2c Fix fish instructions test 2020-02-17 21:46:25 +01: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
Jeffrey 'jf' Lim 137e705db7 Fix (revert) test/version-origin.bats 2020-01-16 23:24:42 +08:00
Jeffrey 'jf' Lim 40db754168 Fix tests for #1203 2020-01-08 16:41:14 +08: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
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
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
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
Marco Hinz 643023d98f
Add tests for shell integration 2017-12-07 02:32:35 +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
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
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ć 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
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
Yamashita, Yuu a456528be8 Keep original ordering of PATH configuration 2016-08-02 00:21:28 +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
Donald Merand 8b0b51a166 convert references to '.' to 'source' for fish shell 2016-02-20 10:27:39 -05: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
Jason Karns 565798d617 Test IFS handling in version-name/version-origin hooks 2016-01-04 09:14:28 -05:00