Commit graph

369 commits

Author SHA1 Message Date
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ć
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
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ć
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
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