Commit graph

360 commits

Author SHA1 Message Date
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ć
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ć
410e05bf8c
Revert support for user-installed gems (#1443) 2022-10-07 12:56:54 +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ć
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ć
6426f852d0
Use absolute path in rbenv init instructions if needed 2022-09-25 22:32:46 +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ä
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ć
38e1fbb08e rbenv 1.2.0 2021-09-29 20:47:10 +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ć
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ć
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
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
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
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
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
Ville Skyttä
a5a1c4d50d Make work in set -u (nounset) mode 2020-05-24 09:08:05 +03: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ć
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
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
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ć
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
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
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
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
Mislav Marohnić
199e598351 Remove ableist language 2018-06-05 16:49: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
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
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ć
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ć
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