pax_global_header00006660000000000000000000000064147375030470014524gustar00rootroot0000000000000052 comment=10e96bfc473c7459a447fbbda12164745a72fd37 rbenv-1.3.2/000077500000000000000000000000001473750304700126435ustar00rootroot00000000000000rbenv-1.3.2/.gitattributes000066400000000000000000000000571473750304700155400ustar00rootroot00000000000000/share/man/man[1-8]/*.[1-8] linguist-generated rbenv-1.3.2/.github/000077500000000000000000000000001473750304700142035ustar00rootroot00000000000000rbenv-1.3.2/.github/dependabot.yml000066400000000000000000000001661473750304700170360ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: 'github-actions' directory: '/' schedule: interval: 'weekly' rbenv-1.3.2/.github/workflows/000077500000000000000000000000001473750304700162405ustar00rootroot00000000000000rbenv-1.3.2/.github/workflows/ci.yml000066400000000000000000000006301473750304700173550ustar00rootroot00000000000000name: 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 rbenv-1.3.2/.github/workflows/lint.yml000066400000000000000000000007641473750304700177400ustar00rootroot00000000000000--- 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 }} rbenv-1.3.2/.github/workflows/release.yml000066400000000000000000000005501473750304700204030ustar00rootroot00000000000000name: 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 }} rbenv-1.3.2/.gitignore000066400000000000000000000001411473750304700146270ustar00rootroot00000000000000/plugins /shims /version /versions /sources /cache /libexec/*.dylib /src/Makefile /src/*.o /gems rbenv-1.3.2/.vimrc000066400000000000000000000000431473750304700137610ustar00rootroot00000000000000set wildignore+=versions/*,cache/* rbenv-1.3.2/CODE_OF_CONDUCT.md000066400000000000000000000064761473750304700154570ustar00rootroot00000000000000# 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 <> * Mislav Marohnić <> * Erik Michaels-Ober <> ## 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/ rbenv-1.3.2/LICENSE000066400000000000000000000020421473750304700136460ustar00rootroot00000000000000Copyright (c) 2013 Sam Stephenson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rbenv-1.3.2/Makefile000066400000000000000000000003221473750304700143000ustar00rootroot00000000000000release_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%=%) $< rbenv-1.3.2/README.md000066400000000000000000000327261473750304700141340ustar00rootroot00000000000000# Seamlessly manage your app’s Ruby environment with rbenv. 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. ## How It Works 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/`. 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 ``` 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. Finally, almost every aspect of rbenv's mechanism is [customizable via plugins][plugins] written in bash. The simplicity of rbenv has its benefits, but also some downsides. See the [comparison of version managers][alternatives] for more details and some alternatives. ## Installation 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. ### Using Package Managers 1. Install rbenv using one of the following approaches. #### Homebrew 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). #### Fedora Fedora has an [official package](https://packages.fedoraproject.org/pkgs/rbenv/rbenv/) which you can install: ```sh sudo dnf install rbenv ``` 2. Set up your shell to load rbenv. ```sh rbenv init ``` 3. Close your Terminal window and open a new one so your changes take effect. That's it! You are now ready to [install some Ruby versions](#installing-ruby-versions). ### Basic Git Checkout > [!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. This will get you going with the latest version of rbenv without needing a system-wide install. 1. Clone rbenv into `~/.rbenv`. ```sh git clone https://github.com/rbenv/rbenv.git ~/.rbenv ``` 2. Set up your shell to load rbenv. ```sh ~/.rbenv/bin/rbenv init ``` If you are curious, see here to [understand what `init` does](#how-rbenv-hooks-into-your-shell). 3. Restart your shell so that these changes take effect. (Opening a new terminal tab will usually do it.) #### Shell completions 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 Tab key in an interactive shell. - The **bash** completion script for rbenv ships with the project and gets [loaded by the `rbenv init` mechanism](#how-rbenv-hooks-into-your-shell). - 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`: ```sh # assuming that rbenv was installed to `~/.rbenv` FPATH=~/.rbenv/completions:"$FPATH" autoload -U compinit compinit ``` - The **fish** completion script for rbenv ships with the fish shell itself and is not maintained by the rbenv project. ### Installing Ruby versions The `rbenv install` command does not ship with rbenv out-of-the-box, but is provided by the [ruby-build][] plugin. 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: ```sh # list latest stable versions: rbenv install -l # list all local versions: rbenv install -L # install a Ruby version: rbenv install 3.1.2 ``` For troubleshooting `BUILD FAILED` scenarios, check the [ruby-build Discussions section](https://github.com/rbenv/ruby-build/discussions/categories/build-failures). > [!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 ` and try again. Check the location where gems are being installed with `gem env`: ```sh gem env home # => ~/.rbenv/versions//lib/ruby/gems/... ``` #### Uninstalling Ruby versions As time goes on, Ruby versions you install will accumulate in your `~/.rbenv/versions` directory. 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 Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix 2.7.0`. The [ruby-build][] plugin provides an `rbenv uninstall` command to automate the removal process. ## Command Reference The main rbenv commands you need to know are: ### rbenv versions Lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version. $ rbenv versions 1.8.7-p352 1.9.2-p290 * 1.9.3-p327 (set by /Users/sam/.rbenv/version) jruby-1.7.1 rbx-1.2.4 ree-1.8.7-2011.03 ### rbenv version Displays the currently active Ruby version, along with information on how it was set. $ 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 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 rehash ### rbenv which Displays the full path to the executable that rbenv will invoke when you run the given command. $ rbenv which irb /Users/sam/.rbenv/versions/1.9.3-p327/bin/irb ### rbenv whence Lists all Ruby versions that contain the specified executable name. $ rbenv whence rackup 1.9.3-p327 jruby-1.7.1 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.
Also see [`rbenv shell`](#rbenv-shell) `RBENV_ROOT` | `~/.rbenv` | Defines the directory under which Ruby versions and shims reside.
Also see `rbenv root` `RBENV_DEBUG` | | Outputs debug information.
Also as: `rbenv --debug ` `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 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 Tests are executed using [Bats](https://github.com/bats-core/bats-core): $ bats test $ bats test/.bats Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/rbenv/rbenv/issues). [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 rbenv-1.3.2/bin/000077500000000000000000000000001473750304700134135ustar00rootroot00000000000000rbenv-1.3.2/bin/rbenv000077700000000000000000000000001473750304700173322../libexec/rbenvustar00rootroot00000000000000rbenv-1.3.2/completions/000077500000000000000000000000001473750304700151775ustar00rootroot00000000000000rbenv-1.3.2/completions/_rbenv000066400000000000000000000004611473750304700163760ustar00rootroot00000000000000#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 } rbenv-1.3.2/completions/rbenv.bash000066400000000000000000000006321473750304700171530ustar00rootroot00000000000000_rbenv() { COMPREPLY=() local word="${COMP_WORDS[COMP_CWORD]}" if [ "$COMP_CWORD" -eq 1 ]; then COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") ) else local words=("${COMP_WORDS[@]}") unset "words[0]" unset "words[$COMP_CWORD]" local completions=$(rbenv completions "${words[@]}") COMPREPLY=( $(compgen -W "$completions" -- "$word") ) fi } complete -F _rbenv rbenv rbenv-1.3.2/libexec/000077500000000000000000000000001473750304700142565ustar00rootroot00000000000000rbenv-1.3.2/libexec/rbenv000077500000000000000000000063251473750304700153260ustar00rootroot00000000000000#!/usr/bin/env bash set -e if [ "$1" = "--debug" ]; then export RBENV_DEBUG=1 shift fi if [ -n "$RBENV_DEBUG" ]; then # 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 fi abort() { { if [ "$#" -eq 0 ]; then cat - else echo "rbenv: $*" fi } >&2 exit 1 } if [ -z "${RBENV_ROOT}" ]; then RBENV_ROOT="${HOME}/.rbenv" else RBENV_ROOT="${RBENV_ROOT%/}" fi export RBENV_ROOT if [ -z "${RBENV_DIR}" ]; then RBENV_DIR="$PWD" else [[ $RBENV_DIR == /* ]] || RBENV_DIR="$PWD/$RBENV_DIR" cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'" RBENV_DIR="$PWD" cd "$OLDPWD" fi 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 # 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 PATH="${plugin_bin}:${PATH}" done export PATH="${libexec_dir}:${PATH}" RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d" if [ ! "${libexec_dir%/*}"/rbenv.d -ef "$RBENV_ROOT"/rbenv.d ]; then # Add rbenv's own `rbenv.d` unless rbenv was cloned to RBENV_ROOT RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${libexec_dir%/*}/rbenv.d" fi 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 RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${plugin_hook}" done RBENV_HOOK_PATH="${RBENV_HOOK_PATH#:}" export RBENV_HOOK_PATH shopt -u nullglob command="$1" case "$command" in "" ) { rbenv---version rbenv-help } | abort ;; -v | --version ) exec rbenv---version ;; -h | --help ) exec rbenv-help ;; * ) command_path="$(type -P "rbenv-$command" || true)" if [ -z "$command_path" ]; then if [ "$command" == "shell" ]; then abort "shell integration not enabled. Run \`rbenv init' for instructions." else abort "no such command \`$command'" fi fi shift 1 if [ "$1" = --help ]; then if [[ "$command" == "sh-"* ]]; then echo "rbenv help \"$command\"" else exec rbenv-help "$command" fi else exec "$command_path" "$@" fi ;; esac rbenv-1.3.2/libexec/rbenv---version000077500000000000000000000011701473750304700171340ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: Display the version of rbenv # # Displays the version number of this rbenv release, including the # current revision from git, if available. # # The format of the git revision is: # -- # where `num_commits` is the number of commits since `version` was # tagged. set -e [ -n "$RBENV_DEBUG" ] && set -x version="1.3.2" git_revision="" 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_revision#v}" fi echo "rbenv ${git_revision:-$version}" rbenv-1.3.2/libexec/rbenv-commands000077500000000000000000000022221473750304700171150ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: List all available rbenv commands # 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 [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo --sh echo --no-sh exit fi exclude_shell= command_prefix="rbenv-" if [ "$1" = "--sh" ]; then command_prefix="rbenv-sh-" shift elif [ "$1" = "--no-sh" ]; then exclude_shell=1 shift fi 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}/${command_prefix}"*; do rbenv_command="${rbenv_command##*rbenv-}" if [[ -z $exclude_shell || $rbenv_command != sh-* ]]; then echo "${rbenv_command##sh-}" fi done fi [[ $PATH_remain == *:* ]] || break PATH_remain="${PATH_remain#*:}" done } | sort | uniq rbenv-1.3.2/libexec/rbenv-completions000077500000000000000000000010511473750304700176470ustar00rootroot00000000000000#!/usr/bin/env bash # Usage: rbenv completions [...] set -e [ -n "$RBENV_DEBUG" ] && set -x COMMAND="$1" if [ -z "$COMMAND" ]; then rbenv-help --usage completions >&2 exit 1 fi # 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 shift exec "$COMMAND_PATH" --complete "$@" fi rbenv-1.3.2/libexec/rbenv-exec000077500000000000000000000021431473750304700162420ustar00rootroot00000000000000#!/usr/bin/env bash # # Summary: Run an executable with the selected Ruby version # # Usage: rbenv exec [...] # # Runs an executable by first preparing PATH so that the selected Ruby # version's `bin' directory is at the front. # # For example, if the currently selected Ruby version is 1.9.3-p327: # rbenv exec bundle install # # is equivalent to: # PATH="$RBENV_ROOT/versions/1.9.3-p327/bin:$PATH" bundle install set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then exec rbenv-shims --short fi RBENV_VERSION="$(rbenv-version-name)" RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then rbenv-help --usage exec >&2 exit 1 fi export RBENV_VERSION RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks exec)" || true for script in "${scripts[@]}"; do # shellcheck disable=SC1090 source "$script" done shift 1 if [ "$RBENV_VERSION" != "system" ]; then export PATH="${RBENV_BIN_PATH}:${PATH}" fi exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@" rbenv-1.3.2/libexec/rbenv-global000077500000000000000000000015761473750304700165670ustar00rootroot00000000000000#!/usr/bin/env bash # # Summary: Set or show the global Ruby version # # Usage: rbenv global # # Sets the global Ruby version. You can override the global version at # any time by setting a directory-specific version with `rbenv local' # or by setting the `RBENV_VERSION' environment variable. # # should be a string matching a Ruby version known to rbenv. # The special version string `system' will use your default system Ruby. # Run `rbenv versions' for a list of available Ruby versions. set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo system exec rbenv-versions --bare fi RBENV_VERSION="$1" RBENV_VERSION_FILE="${RBENV_ROOT}/version" if [ -n "$RBENV_VERSION" ]; then rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" else rbenv-version-file-read "$RBENV_VERSION_FILE" || echo system fi rbenv-1.3.2/libexec/rbenv-help000077500000000000000000000111421473750304700162450ustar00rootroot00000000000000#!/usr/bin/env bash # # Summary: Display help for a command # # Usage: rbenv help [--usage] COMMAND # # Parses and displays help contents from a command's source file. # # A command is considered documented if it starts with a comment block # that has a `Summary:' or `Usage:' section. Usage instructions can # span multiple lines as long as subsequent lines are indented. # The remainder of the comment block is displayed as extended # documentation. set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo --usage exec rbenv-commands fi command_path() { local command="$1" type -P rbenv-"$command" rbenv-sh-"$command" | head -n1 } extract_initial_comment_block() { sed -ne " /^#/ !{ q } s/^#$/# / /^# / { s/^# // p } " } collect_documentation() { 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 = substr($0, 10) next } /^Usage:/ { reading_usage = 1 usage = usage "\n" $0 next } /^( *$| )/ && reading_usage { usage = usage "\n" $0 next } { reading_usage = 0 help = help "\n" $0 } function escape(str) { gsub(/[`\\$"]/, "\\\\&", str) return str } function trim(str) { sub(/^\n*/, "", str) sub(/\n*$/, "", str) return str } END { if (usage || summary) { print "summary=\"" escape(summary) "\"" print "usage=\"" escape(trim(usage)) "\"" print "help=\"" escape(trim(help)) "\"" } } ' } documentation_for() { local filename filename="$(command_path "$1")" if [ -n "$filename" ]; then extract_initial_comment_block < "$filename" | collect_documentation fi } print_summary() { local command="$1" local summary usage help eval "$(documentation_for "$command")" if [ -n "$summary" ]; then printf " %-9s %s\n" "$command" "$summary" fi } print_summaries() { for command; do print_summary "$command" done } print_help() { local command="$1" local summary usage help eval "$(documentation_for "$command")" [ -n "$help" ] || help="$summary" if [ -n "$usage" ] || [ -n "$summary" ]; then if [ -n "$usage" ]; then echo "$usage" else echo "Usage: rbenv ${command}" fi if [ -n "$help" ]; then echo echo "$help" echo fi else echo "Sorry, this command isn't documented yet." >&2 return 1 fi } print_usage() { local command="$1" local summary usage help eval "$(documentation_for "$command")" 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 if [ "$1" = "--usage" ]; then usage="1" shift fi if [ -z "$1" ] || [ "$1" == "rbenv" ]; then if [ -z "$usage" ] && [ -t 1 ] && type -P man >/dev/null; then MANPATH="${BASH_SOURCE%/*}/../share/man:$MANPATH" exec man rbenv fi echo "Usage: rbenv [...]" [ -n "$usage" ] && exit echo echo "Commands to manage available Ruby versions:" 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 "See \`rbenv help ' for information on a specific command." echo "For full documentation, see: https://github.com/rbenv/rbenv#readme" else command="$1" if [ -n "$(command_path "$command")" ]; then if [ -n "$usage" ]; then print_usage "$command" else print_help "$command" fi else echo "rbenv: no such command \`$command'" >&2 exit 1 fi fi rbenv-1.3.2/libexec/rbenv-hooks000077500000000000000000000011271473750304700164420ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: List hook scripts for a given rbenv command # Usage: rbenv hooks set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo exec echo rehash echo version-name echo version-origin echo which exit fi RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then rbenv-help --usage hooks >&2 exit 1 fi IFS=: read -r -a hook_paths <<<"$RBENV_HOOK_PATH" shopt -s nullglob for path in "${hook_paths[@]}"; do for script in "$path/$RBENV_COMMAND"/*.bash; do echo "$script" done done shopt -u nullglob rbenv-1.3.2/libexec/rbenv-init000077500000000000000000000126741473750304700162730ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: Configure the shell environment for rbenv # Usage: rbenv init [...] # rbenv init - [--no-rehash] [] # # 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 [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo - echo --no-rehash echo bash echo fish echo ksh echo zsh exit fi print="" no_rehash="" shells=() while [ $# -gt 0 ]; do case "$1" in "-" ) print=1 ;; "--no-rehash" ) no_rehash=1 ;; * ) shells+=("$1") ;; esac shift done if [ "${#shells[@]}" -eq 0 ]; then shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)" 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 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 ) write_config "${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish" \ "status --is-interactive; and $rbenv_command init - --no-rehash fish | source" ;; * ) printf 'unsupported shell: "%s"\n' "$shell" >&2 status=1 ;; esac done exit $status fi mkdir -p "${RBENV_ROOT}/"{shims,versions} shell="${shells[0]}" case "$shell" in fish ) [ -n "$rbenv_in_path" ] || printf "set -gx PATH '%s/bin' \$PATH\n" "$root" printf "set -gx PATH '%s/shims' \$PATH\n" "$RBENV_ROOT" printf 'set -gx RBENV_SHELL %s\n' "$shell" ;; * ) # shellcheck disable=SC2016 [ -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 if [ -z "$no_rehash" ]; then echo 'command rbenv rehash 2>/dev/null' fi IFS=$'\n' read -d '' -r -a commands <<<"$(rbenv-commands --sh)" || true case "$shell" in fish ) cat < # rbenv local --unset # # Sets the local application-specific Ruby version by writing the # version name to a file named `.ruby-version'. # # When you run a Ruby command, rbenv will look for a `.ruby-version' # file in the current directory and each parent directory. If no such # file is found in the tree, rbenv will use the global Ruby version # specified with `rbenv global'. A version specified with the # `RBENV_VERSION' environment variable takes precedence over local # and global versions. # # should be a string matching a Ruby version known to rbenv. # The special version string `system' will use your default system Ruby. # Run `rbenv versions' for a list of available Ruby versions. set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo --unset echo system exec rbenv-versions --bare fi RBENV_VERSION="$1" if [ "$RBENV_VERSION" = "--unset" ]; then rm -f .ruby-version elif [ -n "$RBENV_VERSION" ]; then rbenv-version-file-write .ruby-version "$RBENV_VERSION" else if version_file="$(rbenv-version-file "$PWD")"; then rbenv-version-file-read "$version_file" else echo "rbenv: no local version configured for this directory" >&2 exit 1 fi fi rbenv-1.3.2/libexec/rbenv-prefix000077500000000000000000000017761473750304700166260ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: Display prefix for a Ruby version # Usage: rbenv prefix [] # # Displays the directory where a Ruby version is installed. If no # version is given, `rbenv prefix' displays the location of the # currently selected version. set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo system exec rbenv-versions --bare fi if [ -n "$1" ]; then export RBENV_VERSION="$1" elif [ -z "$RBENV_VERSION" ]; then RBENV_VERSION="$(rbenv-version-name)" fi if [ "$RBENV_VERSION" = "system" ]; then if RUBY_PATH="$(rbenv-which ruby)"; then RUBY_PATH="${RUBY_PATH%/*}" RBENV_PREFIX_PATH="${RUBY_PATH%/bin}" echo "${RBENV_PREFIX_PATH:-/}" exit else echo "rbenv: system version not found in PATH" >&2 exit 1 fi fi RBENV_PREFIX_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}" if [ ! -d "$RBENV_PREFIX_PATH" ]; then echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2 exit 1 fi echo "$RBENV_PREFIX_PATH" rbenv-1.3.2/libexec/rbenv-rehash000077500000000000000000000117461473750304700166010ustar00rootroot00000000000000#!/usr/bin/env bash # 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 [ -n "$RBENV_DEBUG" ] && set -x SHIM_PATH="${RBENV_ROOT}/shims" PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.rbenv-shim" # Create the shims directory if it doesn't already exist. mkdir -p "$SHIM_PATH" # Ensure only one instance of rbenv-rehash is running at a time by # setting the shell's `noclobber` option and attempting to write to # the prototype shim file. If the file already exists, print a warning # to stderr and exit with a non-zero status. set -o noclobber { echo > "$PROTOTYPE_SHIM_PATH" } 2>| /dev/null || { if [ -w "$SHIM_PATH" ]; then echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" else echo "rbenv: cannot rehash: $SHIM_PATH isn't writable" fi exit 1 } >&2 set +o noclobber # If we were able to obtain a lock, register a trap to clean up the # prototype shim when the process exits. trap remove_prototype_shim EXIT remove_prototype_shim() { 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 # its filename and any arguments to `rbenv exec`. This file is # hard-linked for every executable and then removed. The linking # technique is fast, uses less disk space than unique files, and also # serves as a locking mechanism. create_prototype_shim() { cat > "$PROTOTYPE_SHIM_PATH" </dev/null 2>&1; then rm -f "$SHIM_PATH"/* fi break done } # List basenames of executables for every Ruby version list_executable_names() { local version file rbenv-versions --bare --skip-aliases | \ while read -r version; do for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do echo "${file##*/}" 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 # registered for installation as a shim. In this way, plugins may call # `make_shims` with a glob to register many shims at once. make_shims() { local file shim for file; do shim="${file##*/}" registered_shims+=("$shim") done } # Registers the name of a shim to be generated. register_shim() { registered_shims+=("$1") } # Install all the shims registered via `make_shims` or `register_shim` directly. install_registered_shims() { local shim file for shim in "${registered_shims[@]}"; do file="${SHIM_PATH}/${shim}" [ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file" done } # Once the registered shims have been installed, we make a second pass # over the contents of the shims directory. Any file that is present # in the directory but has not been registered as a shim should be # removed. remove_stale_shims() { local shim local known_shims=" ${registered_shims[*]} " for shim in "$SHIM_PATH"/*; do if [[ "$known_shims" != *" ${shim##*/} "* ]]; then rm -f "$shim" fi done } shopt -s nullglob # Create the prototype shim, then register shims for all known # executables. create_prototype_shim remove_outdated_shims # shellcheck disable=SC2207 registered_shims=( $(list_executable_names | sort -u) ) # Allow plugins to register shims. IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks rehash)" || true for script in "${scripts[@]}"; do # shellcheck disable=SC1090 source "$script" done install_registered_shims remove_stale_shims rbenv-1.3.2/libexec/rbenv-root000077500000000000000000000001571473750304700163040ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: Display the root directory where versions and shims are kept echo "$RBENV_ROOT" rbenv-1.3.2/libexec/rbenv-sh-rehash000077500000000000000000000006741473750304700172070ustar00rootroot00000000000000#!/usr/bin/env bash set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then exec rbenv-rehash --complete fi shell="$(basename "${RBENV_SHELL:-$SHELL}")" # When rbenv shell integration is enabled, delegate to rbenv-rehash, # then tell the shell to empty its command lookup cache. rbenv-rehash case "$shell" in fish ) # no rehash support ;; * ) echo "hash -r 2>/dev/null || true" ;; esac rbenv-1.3.2/libexec/rbenv-sh-shell000077500000000000000000000067001473750304700170400ustar00rootroot00000000000000#!/usr/bin/env bash # # Summary: Set or show the shell-specific Ruby version # # Usage: rbenv shell # rbenv shell - # rbenv shell --unset # # Sets a shell-specific Ruby version by setting the `RBENV_VERSION' # environment variable in your shell. This version overrides local # application-specific versions and the global version. # # should be a string matching a Ruby version known to rbenv. # The special version string `system' will use your default system Ruby. # 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 [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo --unset echo system exec rbenv-versions --bare fi version="$1" shell="$(basename "${RBENV_SHELL:-$SHELL}")" if [ -z "$version" ]; then if [ -z "$RBENV_VERSION" ]; then echo "rbenv: no shell-specific version configured" >&2 exit 1 else echo 'echo "$RBENV_VERSION"' exit fi fi if [ "$version" = "--unset" ]; then case "$shell" in fish ) echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"' echo "set -e RBENV_VERSION" ;; zsh ) echo "typeset -g RBENV_VERSION_OLD=\"\${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 <&2 false end EOS ;; zsh ) cat <&2 false fi EOS ;; * ) cat <&2 false fi EOS ;; esac exit fi # Make sure the specified version is installed. if rbenv-prefix "$version" >/dev/null; then if [ "$version" != "$RBENV_VERSION" ]; then case "$shell" in fish ) echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"' echo "set -gx RBENV_VERSION \"$version\"" ;; zsh ) 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 echo "false" exit 1 fi rbenv-1.3.2/libexec/rbenv-shims000077500000000000000000000005741473750304700164470ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: List existing rbenv shims # Usage: rbenv shims [--short] set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo --short exit fi shopt -s nullglob for command in "${RBENV_ROOT}/shims/"*; do if [ "$1" = "--short" ]; then echo "${command##*/}" else echo "$command" fi done | sort rbenv-1.3.2/libexec/rbenv-version000077500000000000000000000007621473750304700170100ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: Show the current Ruby version and its origin # # Shows the currently selected Ruby version and how it was # selected. To obtain only the version string, use `rbenv # version-name'. set -e [ -n "$RBENV_DEBUG" ] && set -x 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 rbenv-1.3.2/libexec/rbenv-version-file000077500000000000000000000015711473750304700177240ustar00rootroot00000000000000#!/usr/bin/env bash # Usage: rbenv version-file [] # 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 [ -n "$RBENV_DEBUG" ] && set -x target_dir="$1" find_local_version_file() { local root="$1" while ! [[ "$root" =~ ^//[^/]*$ ]]; do if [ -s "${root}/.ruby-version" ]; then echo "${root}/.ruby-version" return 0 fi [ -n "$root" ] || break root="${root%/*}" done return 1 } if [ -n "$target_dir" ]; then find_local_version_file "$target_dir" else find_local_version_file "$RBENV_DIR" || { [ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD" } || echo "${RBENV_ROOT}/version" fi rbenv-1.3.2/libexec/rbenv-version-file-read000077500000000000000000000007651473750304700206410ustar00rootroot00000000000000#!/usr/bin/env bash # Usage: rbenv version-file-read set -e [ -n "$RBENV_DEBUG" ] && set -x VERSION_FILE="$1" if [ -s "$VERSION_FILE" ]; then # Read the first word from the specified version file. Avoid reading it whole. IFS="${IFS}"$'\r' read -n 1024 -d "" -r version _ <"$VERSION_FILE" || : if [ "$version" = ".." ] || [[ $version == */* ]]; then echo "rbenv: invalid version in \`$VERSION_FILE'" >&2 elif [ -n "$version" ]; then echo "$version" exit fi fi exit 1 rbenv-1.3.2/libexec/rbenv-version-file-write000077500000000000000000000006771473750304700210620ustar00rootroot00000000000000#!/usr/bin/env bash # Usage: rbenv version-file-write set -e [ -n "$RBENV_DEBUG" ] && set -x RBENV_VERSION_FILE="$1" RBENV_VERSION="$2" if [ -z "$RBENV_VERSION" ] || [ -z "$RBENV_VERSION_FILE" ]; then rbenv-help --usage version-file-write >&2 exit 1 fi # Make sure the specified version is installed. rbenv-prefix "$RBENV_VERSION" >/dev/null # Write the version out to disk. echo "$RBENV_VERSION" > "$RBENV_VERSION_FILE" rbenv-1.3.2/libexec/rbenv-version-name000077500000000000000000000015431473750304700177240ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: Show the current Ruby version set -e [ -n "$RBENV_DEBUG" ] && set -x if [ -z "$RBENV_VERSION" ]; then RBENV_VERSION_FILE="$(rbenv-version-file)" RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)" 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 echo "system" exit fi version_exists() { local version="$1" [ -d "${RBENV_ROOT}/versions/${version}" ] } if version_exists "$RBENV_VERSION"; then echo "$RBENV_VERSION" elif version_exists "${RBENV_VERSION#ruby-}"; then echo "${RBENV_VERSION#ruby-}" else echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2 exit 1 fi rbenv-1.3.2/libexec/rbenv-version-origin000077500000000000000000000007511473750304700202730ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: Explain how the current Ruby version is set set -e [ -n "$RBENV_DEBUG" ] && set -x 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" else rbenv-version-file fi rbenv-1.3.2/libexec/rbenv-versions000077500000000000000000000033111473750304700171640ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: List installed Ruby versions # Usage: rbenv versions [--bare] [--skip-aliases] # # Lists all Ruby versions found in `$RBENV_ROOT/versions/*'. set -e [ -n "$RBENV_DEBUG" ] && set -x unset bare unset skip_aliases # Provide rbenv completions for arg; do case "$arg" in --complete ) echo --bare echo --skip-aliases exit ;; --bare ) bare=1 ;; --skip-aliases ) skip_aliases=1 ;; * ) rbenv-help --usage versions >&2 exit 1 ;; esac done canonicalize_dir() { { cd "$1" && pwd -P } 2>/dev/null || echo "$1" } versions_dir="${RBENV_ROOT}/versions" if [ -n "$skip_aliases" ]; then versions_dir="$(canonicalize_dir "$versions_dir")" fi list_versions() { local path local target shopt -s nullglob for path in "$versions_dir"/*; do if [ -d "$path" ]; then if [ -n "$skip_aliases" ] && [ -L "$path" ]; then target="$(canonicalize_dir "$path")" [ "${target%/*}" != "$versions_dir" ] || continue fi echo "${path##*/}" fi done shopt -u nullglob } 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 exit 1 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" rbenv-1.3.2/libexec/rbenv-whence000077500000000000000000000013771473750304700165770ustar00rootroot00000000000000#!/usr/bin/env bash # Summary: List all Ruby versions that contain the given executable # Usage: rbenv whence [--path] set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then echo --path exec rbenv-shims --short fi if [ "$1" = "--path" ]; then print_paths="1" shift else print_paths="" fi whence() { local command="$1" rbenv-versions --bare | while read -r version; do path="$(rbenv-prefix "$version")/bin/${command}" if [ -x "$path" ]; then [ "$print_paths" ] && echo "$path" || echo "$version" fi done } RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then rbenv-help --usage whence >&2 exit 1 fi result="$(whence "$RBENV_COMMAND")" [ -n "$result" ] && echo "$result" rbenv-1.3.2/libexec/rbenv-which000077500000000000000000000035621473750304700164260ustar00rootroot00000000000000#!/usr/bin/env bash # # Summary: Display the full path to an executable # # Usage: rbenv which # # Displays the full path to the executable that rbenv will invoke when # you run the given command. set -e [ -n "$RBENV_DEBUG" ] && set -x # Provide rbenv completions if [ "$1" = "--complete" ]; then exec rbenv-shims --short fi remove_from_path() { local path_to_remove="$1" local path_before local result=":${PATH//\~/$HOME}:" while [ "$path_before" != "$result" ]; do path_before="$result" result="${result//:$path_to_remove:/:}" done result="${result%:}" echo "${result#:}" } RBENV_COMMAND="$1" if [ -z "$RBENV_COMMAND" ]; then rbenv-help --usage which >&2 exit 1 fi RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}" if [ "$RBENV_VERSION" = "system" ]; then PATH="$(remove_from_path "${RBENV_ROOT}/shims")" \ RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)" else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi if [[ ! -x "$RBENV_COMMAND_PATH" && -n "$GEM_HOME" && -x "${GEM_HOME}/bin/${RBENV_COMMAND}" ]]; then RBENV_COMMAND_PATH="${GEM_HOME}/bin/${RBENV_COMMAND}" fi IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks which)" || true for script in "${scripts[@]}"; do # shellcheck disable=SC1090 source "$script" done if [ -x "$RBENV_COMMAND_PATH" ]; then echo "$RBENV_COMMAND_PATH" elif [ "$RBENV_VERSION" != "system" ] && [ ! -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2 exit 1 else echo "rbenv: $RBENV_COMMAND: command not found" >&2 versions="$(rbenv-whence "$RBENV_COMMAND" || true)" if [ -n "$versions" ]; then { echo echo "The \`$1' command exists in these Ruby versions:" echo "$versions" | sed 's/^/ /g' echo } >&2 fi exit 127 fi rbenv-1.3.2/rbenv.d/000077500000000000000000000000001473750304700142015ustar00rootroot00000000000000rbenv-1.3.2/rbenv.d/exec/000077500000000000000000000000001473750304700151255ustar00rootroot00000000000000rbenv-1.3.2/rbenv.d/exec/gem-rehash.bash000066400000000000000000000000571473750304700200060ustar00rootroot00000000000000export RUBYLIB="${BASH_SOURCE%.bash}:$RUBYLIB" rbenv-1.3.2/rbenv.d/exec/gem-rehash/000077500000000000000000000000001473750304700171455ustar00rootroot00000000000000rbenv-1.3.2/rbenv.d/exec/gem-rehash/rubygems_plugin.rb000066400000000000000000000025331473750304700227100ustar00rootroot00000000000000hook = lambda do |installer| begin # Ignore gems that aren't installed in locations that rbenv searches for binstubs if installer.spec.executables.any? && [Gem.default_bindir, Gem.bindir(Gem.user_dir)].include?(installer.bin_dir) `rbenv rehash` end rescue warn "rbenv: error in gem-rehash (#{$!.class.name}: #{$!.message})" end end if defined?(Bundler::Installer) && Bundler::Installer.private_method_defined?(:install) && !Bundler::Installer.private_method_defined?(:install_without_rbenv_rehash) Bundler::Installer.class_eval do 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 rbenv-1.3.2/share/000077500000000000000000000000001473750304700137455ustar00rootroot00000000000000rbenv-1.3.2/share/man/000077500000000000000000000000001473750304700145205ustar00rootroot00000000000000rbenv-1.3.2/share/man/man1/000077500000000000000000000000001473750304700153545ustar00rootroot00000000000000rbenv-1.3.2/share/man/man1/rbenv.1000066400000000000000000000070731473750304700165610ustar00rootroot00000000000000'\" 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\fP [\fI\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\fP] .RS 4 View or change the global Ruby version .RE .sp \fBrbenv local\fP [\fI\fP] .RS 4 View or change the local Ruby version .RE .sp \fBrbenv shell\fP [\fI\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\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\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\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ćrbenv-1.3.2/share/man/man1/rbenv.1.adoc000066400000000000000000000051171473750304700174630ustar00rootroot00000000000000= 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* __ [__...] == 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* [__]:: View or change the global Ruby version *rbenv local* [__]:: View or change the local Ruby version *rbenv shell* [__]:: 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* [__]:: (Provided by the *ruby-build* plugin) Download and install a new Ruby version *rbenv rehash*:: Regenerate shims for all known Ruby executables *rbenv which* [__]:: View the executable path that a command resolves to *rbenv init*:: Help bootstrap rbenv into the current shell environment *rbenv help* [__]:: 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 rbenv-1.3.2/src/000077500000000000000000000000001473750304700134325ustar00rootroot00000000000000rbenv-1.3.2/src/Makefile.in000066400000000000000000000004461473750304700155030ustar00rootroot00000000000000../libexec/rbenv-realpath.dylib: @echo "Warning: this Makefile is obsolete and kept only for backwards compatibility." >&2 @echo "You can remove the \`configure && make ...' step from your rbenv setup." >&2 clean: rm -f *.o ../libexec/*.dylib .PHONY: ../libexec/rbenv-realpath.dylib clean rbenv-1.3.2/src/configure000077500000000000000000000002651473750304700153440ustar00rootroot00000000000000#!/usr/bin/env bash # Warning: this configure script is obsolete and kept only for backwards compatibility. set -e src_dir="${0%/*}" cp "$src_dir"/Makefile.in "$src_dir"/Makefile rbenv-1.3.2/test/000077500000000000000000000000001473750304700136225ustar00rootroot00000000000000rbenv-1.3.2/test/--version.bats000066400000000000000000000021251473750304700163140ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper export GIT_DIR="${RBENV_TEST_DIR}/.git" setup() { mkdir -p "$HOME" git config --global user.name "Tester" git config --global user.email "tester@test.local" cd "$RBENV_TEST_DIR" } git_commit() { git commit --quiet --allow-empty -m "empty" } @test "default version" { assert [ ! -e "$RBENV_ROOT" ] run rbenv---version assert_success [[ $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" { git init git remote add origin https://github.com/rbenv/rbenv.git git_commit git tag v0.4.1 git_commit git_commit run rbenv---version assert_success "rbenv 0.4.1-2-g$(git rev-parse --short HEAD)" } @test "prints default version if no tags in git repo" { git init git remote add origin https://github.com/rbenv/rbenv.git git_commit run rbenv---version [[ $output == "rbenv "?.?.? ]] } rbenv-1.3.2/test/commands.bats000066400000000000000000000012651473750304700163020ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper @test "commands" { run rbenv-commands assert_success assert_line "init" assert_line "rehash" assert_line "shell" refute_line "sh-shell" assert_line "echo" } @test "commands --sh" { run rbenv-commands --sh assert_success refute_line "init" assert_line "shell" } @test "commands in path with spaces" { path="${RBENV_TEST_DIR}/my commands" cmd="${path}/rbenv-sh-hello" mkdir -p "$path" touch "$cmd" chmod +x "$cmd" PATH="${path}:$PATH" run rbenv-commands --sh assert_success assert_line "hello" } @test "commands --no-sh" { run rbenv-commands --no-sh assert_success assert_line "init" refute_line "shell" } rbenv-1.3.2/test/completions.bats000066400000000000000000000015601473750304700170330ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper create_command() { bin="${RBENV_TEST_DIR}/bin" mkdir -p "$bin" echo "$2" > "${bin}/$1" chmod +x "${bin}/$1" } @test "command with no completion support" { create_command "rbenv-hello" "#!$BASH echo hello" run rbenv-completions hello assert_success "--help" } @test "command with completion support" { create_command "rbenv-hello" "#!$BASH # Provide rbenv completions if [[ \$1 = --complete ]]; then echo hello else exit 1 fi" run rbenv-completions hello assert_success assert_output < "${bin}/$name" chmod +x "${bin}/$name" } @test "fails with invalid version" { export RBENV_VERSION="2.0" run rbenv-exec ruby -v 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" { export RBENV_VERSION="2.0" create_executable "ruby" "#!/bin/sh" create_executable "rake" "#!/bin/sh" rbenv-rehash run rbenv-completions exec assert_success assert_output <" { export RBENV_VERSION="2.0" # emulate `ruby -S' behavior create_executable "ruby" </dev/null; then \$BASH "\$found" else echo "ruby: no Ruby script found in input (LoadError)" >&2 exit 1 fi else echo 'ruby 2.0 (rbenv test)' fi SH create_executable "rake" < "$RBENV_ROOT/version" run rbenv-global assert_success assert_output "1.2.3" } @test "set RBENV_ROOT/version" { mkdir -p "$RBENV_ROOT/versions/1.2.3" run rbenv-global "1.2.3" assert_success run rbenv-global assert_success "1.2.3" } @test "fail setting invalid RBENV_ROOT/version" { mkdir -p "$RBENV_ROOT" run rbenv-global "1.2.3" assert_failure "rbenv: version \`1.2.3' not installed" } rbenv-1.3.2/test/help.bats000066400000000000000000000052751473750304700154360ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper @test "without args shows summary of common commands" { run rbenv-help assert_success assert_line "Usage: rbenv [...]" assert_line "Commands to manage available Ruby versions:" } @test "usage flag" { run rbenv-help --usage assert_success assert_output "Usage: rbenv [...]" } @test "invalid command" { run rbenv-help hello assert_failure "rbenv: no such command \`hello'" } @test "shows help for a specific command" { mkdir -p "${RBENV_TEST_DIR}/bin" cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < # Summary: Says "hello" to you, from rbenv # This command is useful for saying hello. echo hello SH run rbenv-help hello assert_success assert_output < This command is useful for saying hello. SH } @test "replaces missing extended help with summary text" { mkdir -p "${RBENV_TEST_DIR}/bin" cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < # Summary: Says "hello" to you, from rbenv echo hello SH run rbenv-help hello assert_success assert_output < Says "hello" to you, from rbenv SH } @test "extracts only usage" { mkdir -p "${RBENV_TEST_DIR}/bin" cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < # Summary: Says "hello" to you, from rbenv # This extended help won't be shown. echo hello SH run rbenv-help --usage hello assert_success "Usage: rbenv hello " } @test "empty usage section" { mkdir -p "${RBENV_TEST_DIR}/bin" cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < "${RBENV_TEST_DIR}/bin/rbenv-hello" < # rbenv hi [everybody] # rbenv hola --translate # Summary: Says "hello" to you, from rbenv # Help text. echo hello SH run rbenv-help hello assert_success assert_output < rbenv hi [everybody] rbenv hola --translate Help text. SH } @test "multiline extended help section" { mkdir -p "${RBENV_TEST_DIR}/bin" cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" < # Summary: Says "hello" to you, from rbenv # This is extended help text. # It can contain multiple lines. # # And paragraphs. echo hello SH run rbenv-help hello assert_success assert_output < This is extended help text. It can contain multiple lines. And paragraphs. SH } rbenv-1.3.2/test/hooks.bats000066400000000000000000000035401473750304700156220ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper @test "prints usage help given no argument" { run rbenv-hooks assert_failure "Usage: rbenv hooks " } @test "prints list of hooks" { path1="${RBENV_TEST_DIR}/rbenv.d" path2="${RBENV_TEST_DIR}/etc/rbenv_hooks" RBENV_HOOK_PATH="$path1" create_hook exec "hello.bash" create_hook exec "ahoy.bash" create_hook exec "invalid.sh" create_hook which "boom.bash" RBENV_HOOK_PATH="$path2" create_hook exec "bueno.bash" RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec assert_success assert_output </dev/null" } @test "setup shell completions" { root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" run rbenv-init - bash assert_success assert_line "source '${root}/test/../completions/rbenv.bash'" } @test "detect parent shell" { SHELL=/bin/false run rbenv-init - assert_success assert_line "export RBENV_SHELL=bash" } @test "detect parent shell from script" { mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" cat > myscript.sh < ~/.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 assert_success "writing ~/.config/fish/config.fish: now configured for rbenv." 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 </dev/null" } @test "adds shims to PATH" { export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" run rbenv-init - bash assert_success assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } @test "adds shims to PATH (fish)" { export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" run rbenv-init - fish assert_success assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH" } @test "can add shims to PATH more than once" { export PATH="${RBENV_ROOT}/shims:$PATH" run rbenv-init - bash assert_success assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' } @test "can add shims to PATH more than once (fish)" { export PATH="${RBENV_ROOT}/shims:$PATH" run rbenv-init - fish assert_success assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH" } @test "outputs sh-compatible syntax" { run rbenv-init - bash assert_success assert_line ' case "$command" in' run rbenv-init - zsh assert_success assert_line ' case "$command" in' } @test "outputs fish-specific syntax (fish)" { run rbenv-init - fish assert_success assert_line ' switch "$command"' refute_line ' case "$command" in' } rbenv-1.3.2/test/libexec/000077500000000000000000000000001473750304700152355ustar00rootroot00000000000000rbenv-1.3.2/test/libexec/rbenv-echo000077500000000000000000000002351473750304700172130ustar00rootroot00000000000000#!/usr/bin/env bash # Usage: rbenv echo [-F] VAR if [[ $1 == -F* ]]; then sep="${1:2}" echo "${!2}" | tr "${sep:-:}" $'\n' else echo "${!1}" fi rbenv-1.3.2/test/local.bats000066400000000000000000000023761473750304700155770ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper setup() { mkdir -p "${RBENV_TEST_DIR}/myproject" cd "${RBENV_TEST_DIR}/myproject" } @test "no version" { assert [ ! -e "${PWD}/.ruby-version" ] run rbenv-local assert_failure "rbenv: no local version configured for this directory" } @test "local version" { echo "1.2.3" > .ruby-version run rbenv-local assert_success "1.2.3" } @test "discovers version file in parent directory" { echo "1.2.3" > .ruby-version mkdir -p "subdir" && cd "subdir" run rbenv-local assert_success "1.2.3" } @test "ignores RBENV_DIR" { echo "1.2.3" > .ruby-version mkdir -p "$HOME" echo "2.0-home" > "${HOME}/.ruby-version" RBENV_DIR="$HOME" run rbenv-local assert_success "1.2.3" } @test "sets local version" { mkdir -p "${RBENV_ROOT}/versions/1.2.3" run rbenv-local 1.2.3 assert_success "" assert [ "$(cat .ruby-version)" = "1.2.3" ] } @test "changes local version" { echo "1.0-pre" > .ruby-version mkdir -p "${RBENV_ROOT}/versions/1.2.3" run rbenv-local assert_success "1.0-pre" run rbenv-local 1.2.3 assert_success "" assert [ "$(cat .ruby-version)" = "1.2.3" ] } @test "unsets local version" { touch .ruby-version run rbenv-local --unset assert_success "" assert [ ! -e .ruby-version ] } rbenv-1.3.2/test/prefix.bats000066400000000000000000000022031473750304700157670ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper @test "prefix" { mkdir -p "${RBENV_TEST_DIR}/myproject" cd "${RBENV_TEST_DIR}/myproject" echo "1.2.3" > .ruby-version mkdir -p "${RBENV_ROOT}/versions/1.2.3" run rbenv-prefix assert_success "${RBENV_ROOT}/versions/1.2.3" } @test "prefix for invalid version" { RBENV_VERSION="1.2.3" run rbenv-prefix assert_failure "rbenv: version \`1.2.3' not installed" } @test "prefix for system" { mkdir -p "${RBENV_TEST_DIR}/bin" touch "${RBENV_TEST_DIR}/bin/ruby" chmod +x "${RBENV_TEST_DIR}/bin/ruby" RBENV_VERSION="system" run rbenv-prefix assert_success "$RBENV_TEST_DIR" } @test "prefix for system in /" { mkdir -p "${BATS_TEST_DIRNAME}/libexec" cat >"${BATS_TEST_DIRNAME}/libexec/rbenv-which" </dev/null || true" assert [ -x "${RBENV_ROOT}/shims/ruby" ] } @test "sh-rehash in fish" { create_executable "2.0" "ruby" RBENV_SHELL=fish run rbenv-sh-rehash assert_success "" assert [ -x "${RBENV_ROOT}/shims/ruby" ] } rbenv-1.3.2/test/run000077500000000000000000000001001473750304700143430ustar00rootroot00000000000000#!/usr/bin/env bash set -e exec bats ${CI:+--tap} "${@:-test}" rbenv-1.3.2/test/shell.bats000066400000000000000000000044541473750304700156130ustar00rootroot00000000000000#!/usr/bin/env bats 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" { mkdir -p "${RBENV_TEST_DIR}/myproject" cd "${RBENV_TEST_DIR}/myproject" echo "1.2.3" > .ruby-version RBENV_VERSION="" run rbenv-sh-shell assert_failure "rbenv: no shell-specific version configured" } @test "shell version" { RBENV_SHELL=bash RBENV_VERSION="1.2.3" run rbenv-sh-shell assert_success 'echo "$RBENV_VERSION"' } @test "shell version (fish)" { RBENV_SHELL=fish RBENV_VERSION="1.2.3" run rbenv-sh-shell 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" { RBENV_SHELL=bash run rbenv-sh-shell --unset assert_success assert_output </dev/null || echo "$RBENV_TEST_DIR")" export RBENV_ROOT="${RBENV_TEST_DIR}/root" 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="${RBENV_TEST_DIR}/bin:$PATH" PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" PATH="${RBENV_ROOT}/shims:$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 teardown() { rm -rf "$RBENV_TEST_DIR" } flunk() { { if [ "$#" -eq 0 ]; then cat - else echo "$@" fi } | sed "s:${RBENV_TEST_DIR}:TEST_DIR:g" >&2 return 1 } assert_success() { if [ "$status" -ne 0 ]; then flunk "command failed with exit status $status" elif [ "$#" -gt 0 ]; then assert_output "$1" fi } assert_failure() { if [ "$status" -eq 0 ]; then flunk "expected failed exit status" elif [ "$#" -gt 0 ]; then assert_output "$1" fi } assert_equal() { if [ "$1" != "$2" ]; then { echo "expected: $1" echo "actual: $2" } | flunk fi } assert_output() { local expected if [ $# -eq 0 ]; then expected="$(cat -)" else expected="$1" fi assert_equal "$expected" "$output" } assert_line() { if [ "$1" -ge 0 ] 2>/dev/null; then assert_equal "$2" "${lines[$1]}" else local line for line in "${lines[@]}"; do if [ "$line" = "$1" ]; then return 0; fi done flunk "expected line \`$1'" fi } refute_line() { if [ "$1" -ge 0 ] 2>/dev/null; then local num_lines="${#lines[@]}" if [ "$1" -lt "$num_lines" ]; then flunk "output has $num_lines lines" fi else local line for line in "${lines[@]}"; do if [ "$line" = "$1" ]; then flunk "expected to not find line \`$line'" fi done fi } assert() { if ! "$@"; then flunk "failed: $@" fi } # Output a modified PATH that ensures that the given executable is not present, # but in which system utils necessary for rbenv operation are still available. path_without() { local exe="$1" local path=":${PATH}:" local found alt util for found in $(type -aP "$exe"); do found="${found%/*}" if [ "$found" != "${RBENV_ROOT}/shims" ]; then alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" mkdir -p "$alt" for util in bash head cut readlink greadlink sed sort awk; do if [ -x "${found}/$util" ]; then ln -s "${found}/$util" "${alt}/$util" fi done path="${path/:${found}:/:${alt}:}" fi done path="${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 } rbenv-1.3.2/test/version-file-read.bats000066400000000000000000000036361473750304700200200ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper setup() { mkdir -p "${RBENV_TEST_DIR}/myproject" cd "${RBENV_TEST_DIR}/myproject" } @test "fails without arguments" { run rbenv-version-file-read assert_failure "" } @test "fails for invalid file" { run rbenv-version-file-read "non-existent" assert_failure "" } @test "fails for blank file" { echo > my-version run rbenv-version-file-read my-version assert_failure "" } @test "reads simple version file" { cat > my-version <<<"1.9.3" run rbenv-version-file-read my-version assert_success "1.9.3" } @test "ignores leading spaces" { cat > my-version <<<" 1.9.3" run rbenv-version-file-read my-version assert_success "1.9.3" } @test "reads only the first word from file" { cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi" run rbenv-version-file-read my-version assert_success "1.9.3-p194@tag" } @test "loads only the first line in file" { cat > my-version < my-version < my-version run rbenv-version-file-read my-version assert_success "1.8.7" } @test "ignores carriage returns" { cat > my-version <<< $'1.9.3\r' run rbenv-version-file-read my-version 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'" } rbenv-1.3.2/test/version-file-write.bats000066400000000000000000000014161473750304700202310ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper setup() { mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" } @test "invocation without 2 arguments prints usage" { run rbenv-version-file-write assert_failure "Usage: rbenv version-file-write " run rbenv-version-file-write "one" "" assert_failure } @test "setting nonexistent version fails" { assert [ ! -e ".ruby-version" ] run rbenv-version-file-write ".ruby-version" "1.8.7" assert_failure "rbenv: version \`1.8.7' not installed" assert [ ! -e ".ruby-version" ] } @test "writes value to arbitrary file" { mkdir -p "${RBENV_ROOT}/versions/1.8.7" assert [ ! -e "my-version" ] run rbenv-version-file-write "${PWD}/my-version" "1.8.7" assert_success "" assert [ "$(cat my-version)" = "1.8.7" ] } rbenv-1.3.2/test/version-file.bats000066400000000000000000000035041473750304700171010ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper setup() { mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" } create_file() { mkdir -p "$(dirname "$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" { assert [ ! -e "${RBENV_ROOT}/version" ] assert [ ! -e ".ruby-version" ] run rbenv-version-file assert_success "${RBENV_ROOT}/version" } @test "in current directory" { create_file ".ruby-version" run rbenv-version-file assert_success "${RBENV_TEST_DIR}/.ruby-version" } @test "in parent directory" { create_file ".ruby-version" mkdir -p project cd project run rbenv-version-file assert_success "${RBENV_TEST_DIR}/.ruby-version" } @test "topmost file has precedence" { create_file ".ruby-version" create_file "project/.ruby-version" cd project run rbenv-version-file assert_success "${RBENV_TEST_DIR}/project/.ruby-version" } @test "RBENV_DIR has precedence over PWD" { create_file "widget/.ruby-version" create_file "project/.ruby-version" cd project RBENV_DIR="${RBENV_TEST_DIR}/widget" run rbenv-version-file assert_success "${RBENV_TEST_DIR}/widget/.ruby-version" } @test "PWD is searched if RBENV_DIR yields no results" { mkdir -p "widget/blank" create_file "project/.ruby-version" cd project RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file 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 "" } rbenv-1.3.2/test/version-name.bats000066400000000000000000000035131473750304700171020ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper create_version() { mkdir -p "${RBENV_ROOT}/versions/$1" } setup() { mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" } @test "no version selected" { assert [ ! -d "${RBENV_ROOT}/versions" ] run rbenv-version-name assert_success "system" } @test "system version is not checked for existence" { RBENV_VERSION=system run rbenv-version-name 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 < ".ruby-version" <<<"1.8.7" run rbenv-version-name assert_success "1.8.7" RBENV_VERSION=1.9.3 run rbenv-version-name assert_success "1.9.3" } @test "local file has precedence over global" { create_version "1.8.7" create_version "1.9.3" cat > "${RBENV_ROOT}/version" <<<"1.8.7" run rbenv-version-name assert_success "1.8.7" cat > ".ruby-version" <<<"1.9.3" run rbenv-version-name assert_success "1.9.3" } @test "missing version" { RBENV_VERSION=1.2 run rbenv-version-name assert_failure "rbenv: version \`1.2' is not installed (set by RBENV_VERSION environment variable)" } @test "version with prefix in name" { create_version "1.8.7" cat > ".ruby-version" <<<"ruby-1.8.7" run rbenv-version-name assert_success assert_output "1.8.7" } rbenv-1.3.2/test/version-origin.bats000066400000000000000000000025151473750304700174520ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper setup() { mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" } @test "reports global file even if it doesn't exist" { assert [ ! -e "${RBENV_ROOT}/version" ] run rbenv-version-origin assert_success "${RBENV_ROOT}/version" } @test "detects global file" { mkdir -p "$RBENV_ROOT" touch "${RBENV_ROOT}/version" run rbenv-version-origin assert_success "${RBENV_ROOT}/version" } @test "detects RBENV_VERSION" { RBENV_VERSION=1 run rbenv-version-origin assert_success "RBENV_VERSION environment variable" } @test "detects local file" { echo "system" > .ruby-version run rbenv-version-origin assert_success "${PWD}/.ruby-version" } @test "reports from hook" { create_hook version-origin test.bash <<<"RBENV_VERSION_ORIGIN=plugin" RBENV_VERSION=1 run rbenv-version-origin assert_success "plugin" } @test "carries original IFS within hooks" { create_hook version-origin hello.bash < ".ruby-version" <<<"1.9.3" run rbenv-version assert_success "1.9.3 (set by ${PWD}/.ruby-version)" } @test "set by global file" { create_version "1.9.3" cat > "${RBENV_ROOT}/version" <<<"1.9.3" run rbenv-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)" } rbenv-1.3.2/test/versions.bats000066400000000000000000000057151473750304700163550ustar00rootroot00000000000000#!/usr/bin/env bats load test_helper create_version() { mkdir -p "${RBENV_ROOT}/versions/$1" } setup() { mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" } stub_system_ruby() { local stub="${RBENV_TEST_DIR}/bin/ruby" mkdir -p "$(dirname "$stub")" touch "$stub" && chmod +x "$stub" } @test "no versions installed" { stub_system_ruby assert [ ! -d "${RBENV_ROOT}/versions" ] run rbenv-versions assert_success "* system" } @test "not even system ruby available" { PATH="$(path_without ruby)" run rbenv-versions assert_failure assert_output "Warning: no Ruby detected on the system" } @test "bare output no versions installed" { assert [ ! -d "${RBENV_ROOT}/versions" ] run rbenv-versions --bare assert_success "" } @test "single version installed" { stub_system_ruby create_version "1.9" run rbenv-versions assert_success assert_output < "${RBENV_ROOT}/version" <<<"1.9.3" run rbenv-versions assert_success assert_output < ".ruby-version" <<<"1.9.3" run rbenv-versions assert_success assert_output < "${RBENV_ROOT}/version" <<<"1.8" create_executable "1.8" "ruby" mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" RBENV_VERSION='' run rbenv-which ruby assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby" }