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>
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.
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".
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>
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.
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>
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`.
1. On systems with `readlink -f`, use that to canonicalize the path to libexec directory;
2. Otherwise, resolve symlinks recursively rather than just once.
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.
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".
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`.
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.
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