Runtime Executor (asdf rust clone)

Related tags

GUI rtx
Overview

rtx

Crates.io License: MIT CI Codecov Discord

Polyglot runtime manager (asdf rust clone)

Quickstart

Install rtx (other methods here):

$ https://rtx.jdxcode.com/rtx-latest-macos-arm64 > ~/bin/rtx
$ rtx --version
rtx 1.5.1

Hook rtx into to your shell. This will automatically add ~/bin to PATH if it isn't already. (choose one, and open a new shell session for the changes to take effect):

$ echo 'eval "$(~/bin/rtx activate bash)"' >> ~/.bashrc
$ echo 'eval "$(~/bin/rtx activate zsh)"' >> ~/.zshrc
$ echo '~/bin/rtx activate fish | source' >> ~/.config/fish/config.fish

Install a runtime and set it as the default:

$ rtx install nodejs@18
$ rtx global nodejs@18
$ node -v
v18.10.9

Note

rtx install is optional, rtx global will prompt to install the runtime if it's not already installed. This is configurable in ~/.config/rtx/config.toml.

About

rtx is a tool for managing programming language and tool versions. For example, use this to install a particular version of node.js and ruby for a project. Using rtx activate, you can have your shell automatically switch to the correct node and ruby versions when you cd into the project's directory. Other projects on your machine can use a different set of versions.

rtx is inspired by asdf and uses asdf's vast plugin ecosystem under the hood. However, it is much faster than asdf and has a more friendly user experience. For more on how rtx compares to asdf, see below. The goal of this project was to create a better front-end to asdf.

It uses the same .tool-versions file that asdf uses. It's also compatible with idiomatic version files like .node-version and .ruby-version. See Legacy Version Files below.

Come chat about rtx on discord.

How it works

rtx installs as a shell extension (e.g. rtx activate zsh) that sets the PATH environment variable to point your shell to the correct runtime binaries. When you cd into a directory containing a .tool-versions file, rtx will automatically activate the correct versions.

Every time your prompt starts it will call rtx hook-env to fetch new environment variables. This should be very fast and it exits early if the the directory wasn't changed or the .tool-version files haven't been updated. On my machine this takes 4ms in the fast case, 14ms in the slow case. See Performance for more on this topic.

Unlike asdf which uses shim files to dynamically locate runtimes when they're called, rtx modifies PATH ahead of time so the runtimes are called directly. This is not only faster since it avoids any overhead, but it also makes it so commands like which node work as expected. This also means there isn't any need to run asdf reshim after installing new runtime binaries.

Common example commands

rtx install [email protected]       Install a specific version number
rtx install [email protected]         Install a fuzzy version number
rtx local nodejs@20             Use node-20.x in current project
rtx global nodejs@20            Use node-20.x as default

rtx install nodejs              Install the latest available version
rtx local nodejs@latest         Use latest node in current directory
rtx global nodejs@system        Use system node as default

rtx x nodejs@20 -- node app.js  Run `node app.js` with the PATH pointing to node-20.x

Installation

Warning

Regardless of the installation method, when uninstalling rtx, remove RTX_DATA_DIR folder (usually ~/.local/share/rtx) to fully clean up.

Standalone

Note that it isn't necessary for rtx to be on PATH. If you run the activate script in your rc file, rtx will automatically add itself to PATH.

$ curl https://rtx.jdxcode.com/install.sh | sh

Note

There isn't currently an autoupdater in rtx. So if you use this method you'll need to remember to fetch a new version manually for bug/feature fixes. I'm not sure if I'll ever add an autoupdater because it might be disruptive to autoupdate to a major version that has breaking changes.

or if you're allergic to | sh:

$ curl https://rtx.jdxcode.com/rtx-latest-macos-arm64 > /usr/local/bin/rtx

It doesn't matter where you put it. So use ~/bin, /usr/local/bin, ~/.local/share/rtx/bin/rtx or whatever.

Supported architectures:

  • x64
  • arm64

Supported platforms:

  • macos
  • linux

If you need something else, compile it with cargo.

Homebrew

$ brew install jdxcode/tap/rtx

Cargo

Build from source with Cargo.

$ cargo install rtx-cli

Do it faster with cargo-binstall:

$ cargo install cargo-binstall
$ cargo binstall rtx-cli

npm

rtx is available on npm as precompiled binaries. This isn't a node.js package, just distributed via npm. It can be useful for JS projects that want to setup rtx via package.json or npx.

$ npm install -g @jdxcode/rtx

Or use npx if you just want to test it out for a single command without fully installing:

$ npx @jdxcode/rtx exec [email protected] -- python some_script.py

GitHub Releases

Download the latest release from GitHub.

$ curl https://github.com/jdxcode/rtx/releases/download/v1.5.1/rtx-v1.5.1-linux-x64 | tar -xJv
$ mv rtx/bin/rtx /usr/local/bin

apt

For installation on Ubuntu/Debian:

wget -qO - https://rtx.jdxcode.com/gpg-key.pub | gpg --dearmor | sudo tee /usr/share/keyrings/rtx-archive-keyring.gpg 1> /dev/null
echo "deb [signed-by=/usr/share/keyrings/rtx-archive-keyring.gpg arch=amd64] https://rtx.jdxcode.com/deb stable main" | sudo tee /etc/apt/sources.list.d/rtx.list
sudo apt update
sudo apt install -y rtx

Warning

If you're on arm64 you'll need to run the following:

echo "deb [signed-by=/usr/share/keyrings/rtx-archive-keyring.gpg arch=arm64] https://rtx.jdxcode.com/deb stable main" | sudo tee /etc/apt/sources.list.d/rtx.list

dnf

For Fedora, CentOS, Amazon Linux, RHEL and other dnf-based distributions:

dnf install -y dnf-plugins-core
dnf config-manager --add-repo https://rtx.jdxcode.com/rpm/rtx.repo
dnf install -y rtx

yum

yum install -y yum-utils
yum-config-manager --add-repo https://rtx.jdxcode.com/rpm/rtx.repo
yum install -y rtx

apk (coming soon)

For Alpine Linux:

apk add rtx --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/

aur

For Arch Linux:

git clone https://aur.archlinux.org/rtx.git
cd rtx
makepkg -si

Other Shells

Bash

$ echo 'eval "$(rtx activate bash)"' >> ~/.bashrc

Fish

$ echo 'rtx activate fish | source' >> ~/.config/fish/config.fish

Xonsh

Since .xsh files are not compiled you may shave a bit off startup time by using a pure Python import: add the code below to, for example, ~/.config/xonsh/rtx.py config file and import rtx it in ~/.config/xonsh/rc.xsh:

from pathlib        	import Path
from xonsh.built_ins	import XSH

ctx = XSH.ctx
rtx_init = subprocess.run([Path('~/bin/rtx').expanduser(),'activate','xonsh'],capture_output=True,encoding="UTF-8").stdout
XSH.builtins.execx(rtx_init,'exec',ctx,filename='rtx')

Or continue to use rc.xsh/.xonshrc:

echo 'execx($(~/bin/rtx activate xonsh))' >> ~/.config/xonsh/rc.xsh # or ~/.xonshrc

Given that rtx replaces both shell env $PATH and OS environ PATH, watch out that your configs don't have these two set differently (might throw os.environ['PATH'] = xonsh.built_ins.XSH.env.get_detyped('PATH') at the end of a config to make sure they match)

Something else?

Adding a new shell is not hard at all since very little shell code is in this project. See here for how the others are implemented. If your shell isn't currently supported I'd be happy to help you get yours integrated.

Configuration

.tool-versions

The .tool-versions file is used to specify the runtime versions for a project. An example of this is:

nodejs      20.0.0  # comments are allowed
ruby        3       # can be fuzzy version
shellcheck  latest  # also supports "latest"
jq          1.6

Create .tool-versions files manually, or use rtx local to create them automatically. See the asdf docs for more info on this file format.

Legacy version files

RTX supports "legacy version files" just like asdf.

It's behind a config setting "legacy_version_file", but it's enabled by default (asdf defaults to disabled). You can disable these with rtx settings set legacy_version_file false. There is a performance cost to having these when they're parsed as it's performed by the plugin in bin/parse-version-file. However these are cached so it's not a huge deal. You may not even notice.

These are ideal for setting the runtime version of a project without forcing other developers to use a specific tool like rtx/asdf.

They support aliases, which means you can (finally) have an .nvmrc file with lts/hydrogen and it will work in rtx and nvm. This wasn't possible with asdf.

Here are some of the supported legacy version files:

Plugin "Legacy" (Idiomatic) Files
crystal .crystal-version
elixir .exenv-version
golang .go-version, go.mod
java .java-version
nodejs .nvmrc, .node-version
python .python-version
ruby .ruby-version, Gemfile
terraform .terraform-version, .packer-version, main.tf
yarn .yvmrc

Note

asdf calls these "legacy version files" so we do too. I think this is a bad name since it implies that they shouldn't be used—which is definitely not the case IMO. I prefer the term "idiomatic" version files since they're version files not specific to asdf/rtx and can be used by other tools. (.npmrc being a notable exception, which is tied to a specific tool.)

Global config: ~/.config/rtx/config.toml

rtx can be configured in ~/.config/rtx/config.toml. The following options are available (defaults shown):

# whether to prompt to install plugins and runtimes if they're not already installed
missing_runtime_behavior = 'prompt' # other options: 'ignore', 'warn', 'prompt', 'autoinstall'

# plugins can read the versions files used by other version managers (if enabled by the plugin)
# for example, .nvmrc in the case of nodejs's nvm
legacy_version_file = true         # enabled by default (different than asdf)

# configure `rtx install` to always keep the downloaded archive
always_keep_download = false        # deleted after install by default

# configure how frequently (in minutes) to fetch updated plugin repository changes
# this is updated whenever a new runtime is installed
plugin_autoupdate_last_check_duration = 10080 # (one week) set to 0 to disable updates

# configure how frequently (in minutes) to fetch updated shortname repository changes
# note this is not plugins themselves, it's the shortname mappings
# e.g.: nodejs -> https://github.com/asdf-vm/asdf-nodejs.git
plugin_repository_last_check_duration = 10080 # (one week) set to 0 to disable updates

verbose = false # see explanation under `RTX_VERBOSE`

# disables the short name repository (described above)
disable_plugin_short_name_repository = false

[alias.nodejs]
my_custom_node = '18'  # makes `rtx install nodejs@my_custom_node` install node-18.x
                       # this can also be specified in a plugin (see below in "Aliases")

These settings can also be managed with rtx settings ls|get|set|unset.

Environment variables

rtx can also be configured via environment variables. The following options are available:

RTX_MISSING_RUNTIME_BEHAVIOR

This is the same as the missing_runtime_behavior config option in ~/.config/rtx/config.toml.

RTX_DATA_DIR

This is the directory where rtx stores its data. The default is ~/.local/share/rtx.

$ RTX_MISSING_RUNTIME_BEHAVIOR=ignore rtx install nodejs@20
$ RTX_NODEJS_VERSION=20 rtx exec -- node --version

RTX_CONFIG_FILE

This is the path to the config file. The default is ~/.config/rtx/config.toml. (Or $XDG_CONFIG_HOME/config.toml if that is set)

RTX_DEFAULT_TOOL_VERSIONS_FILENAME

Set to something other than ".tool-versions" to have rtx look for configuration with alternate names.

RTX_${PLUGIN}_VERSION

Set the version for a runtime. For example, RTX_NODEJS_VERSION=20 will use [email protected] regardless of what is set in .tool-versions.

RTX_LEGACY_VERSION_FILE

Plugins can read the versions files used by other version managers (if enabled by the plugin) for example, .nvmrc in the case of nodejs's nvm.

RTX_LOG_LEVEL=trace|debug|info|warn|error

Can also use RTX_DEBUG=1, RTX_TRACE=1, and RTX_QUIET=1. These adjust the log output to the screen.

RTX_LOG_FILE=~/.rtx/rtx.log

Output logs to a file.

RTX_LOG_FILE_LEVEL=trace|debug|info|warn|error

Same as RTX_LOG_LEVEL but for the log file output level. This is useful if you want to store the logs but not have them litter your display.

RTX_VERBOSE=1

This shows the installation output during rtx install and rtx plugin install. This should likely be merged so it behaves the same as RTX_DEBUG=1 and we don't have 2 configuration for the same thing, but for now it is it's own config.

RTX_HIDE_OUTDATED_BUILD=1

If a release is 12 months old, it will show a warning message every time it launches:

rtx has not been updated in over a year. Please update to the latest version.

You likely do not want to be using rtx if it is that old. I'm doing this instead of autoupdating. If, for some reason, you want to stay on some old version, you can hide this message with RTX_HIDE_OUTDATED_BUILD=1.

Aliases

rtx supports aliasing the versions of runtimes. One use-case for this is to define aliases for LTS versions of runtimes. For example, you may want to specify lts/hydrogen as the version for [email protected]. So you can use the runtime with nodejs lts/hydrogen in .tool-versions.

User aliases can be created by adding an alias.<PLUGIN> section to ~/.config/rtx/config.toml:

[alias.nodejs]
my_custom_18 = '18'

Plugins can also provide aliases via a bin/list-aliases script. Here is an example showing node.js versions:

#!/usr/bin/env bash

echo "lts/hydrogen 18"
echo "lts/gallium 16"
echo "lts/fermium 14"

Note:

Because this is rtx-specific functionality not currently used by asdf it isn't likely to be in any plugin currently, but plugin authors can add this script without impacting asdf users.

Plugins

rtx uses asdf's plugin ecosystem under the hood. See https://github.com/asdf-vm/asdf-plugins for a list.

FAQs

I don't want to put a .tool-versions file into my project since git shows it as an untracked file.

You can make git ignore these files in 3 different ways:

  • Adding .tool-versions to project's .gitignore file. This has the downside that you need to commit the change to the ignore file.
  • Adding .tool-versions to project's .git/info/exclude. This file is local to your project so there is no need to commit it.
  • Adding .tool-versions to global gitignore (core.excludesFile). This will cause git to ignore .tool-versions files in all projects. You can explicitly add one to a project if needed with git add --force .tool-versions.

How do I create my own plugin?

Just follow the asdf docs. Everything should work the same. If it isn't, please open an issue.

rtx is failing or not working right

First try setting RTX_LOG_LEVEL=debug or RTX_LOG_LEVEL=trace and see if that gives you more information. You can also set RTX_LOG_FILE=/path/to/logfile to write the logs to a file.

If something is happening with the activate hook, you can try disabling it and calling eval "$(rtx hook-env)" manually. It can also be helpful to use rtx env to see what environment variables it wants to use.

Lastly, there is an rtx doctor command. It doesn't have much in it but I hope to add more functionality to that to help debug issues.

Windows support?

This is unlikely to ever happen since this leverages the vast ecosystem of asdf plugins which are built on Bash scripts. At some point it may be worth exploring an alternate plugin format that would be Windows compatible.

Commands

rtx activate

Enables rtx to automatically modify runtimes when changing directory

This should go into your shell's rc file.
Otherwise, it will only take effect in the current session.
(e.g. ~/.bashrc)

Usage: activate [OPTIONS] [SHELL_TYPE]

Arguments:
  [SHELL_TYPE]
          Shell type to generate the script for
          
          [possible values: bash, fish, xonsh, zsh]

Options:
  -q, --quiet
          Hide the "rtx: <PLUGIN>@<VERSION>" message when changing directories

  -h, --help
          Print help (see a summary with '-h')


Examples:
    $ eval "$(rtx activate bash)"
    $ eval "$(rtx activate zsh)"
    $ rtx activate fish | source
    $ execx($(rtx activate xonsh))

rtx alias ls

List aliases
Shows the aliases that can be specified.
These can come from user config or from plugins in `bin/list-aliases`.

For user config, aliases are defined like the following in `~/.config/rtx/config.toml`:

  [alias.nodejs]
  lts = "18.0.0"

Usage: ls [OPTIONS]

Options:
  -p, --plugin <PLUGIN>
          Show aliases for <PLUGIN>

  -h, --help
          Print help (see a summary with '-h')

Examples:
  $ rtx aliases
  nodejs    lts/hydrogen   18.0.0

rtx complete

generate shell completions

Usage: complete --shell <SHELL>

Options:
  -s, --shell <SHELL>
          shell type
          
          [possible values: bash, elvish, fish, powershell, zsh]

  -h, --help
          Print help (see a summary with '-h')


Examples:
  $ rtx complete

rtx current

Shows currently active, and installed runtime versions

This is similar to `rtx list --current`, but this
only shows the runtime and/or version so it's
designed to fit into scripts more easily.

Usage: current [PLUGIN]

Arguments:
  [PLUGIN]
          plugin to show versions of
          
          e.g.: ruby, nodejs

Options:
  -h, --help
          Print help (see a summary with '-h')


Examples:

  $ rtx current
  [email protected]
  [email protected]
  [email protected]

  $ rtx current nodejs
  18.13.0

rtx deactivate

disable rtx for current shell session

This can be used to temporarily disable rtx in a shell session.

Usage: deactivate [SHELL_TYPE]

Arguments:
  [SHELL_TYPE]
          shell type to generate the script for
          
          [possible values: bash, fish, xonsh, zsh]

Options:
  -h, --help
          Print help (see a summary with '-h')


Examples:
    $ eval "$(rtx deactivate bash)"
    $ eval "$(rtx deactivate zsh)"
    $ rtx deactivate fish | source
    $ execx($(rtx deactivate xonsh))

rtx direnv activate

Output direnv function to use rtx inside direnv

See https://github.com/jdxcode/rtx#direnv for more information

Because this generates the legacy files based on currently installed plugins,
you should run this command after installing new plugins. Otherwise
direnv may not know to update environment variables when legacy file versions change.

Usage: activate

Options:
  -h, --help
          Print help (see a summary with '-h')


Examples:
    $ rtx direnv activate > ~/.config/direnv/lib/use_rtx.sh
    $ echo 'use rtx' > .envrc
    $ direnv allow

rtx doctor

Check rtx installation for possible problems.

Usage: doctor

Options:
  -h, --help
          Print help (see a summary with '-h')


Examples:
  $ rtx doctor
  [WARN] plugin nodejs is not installed

rtx env

exports env vars to activate rtx in a single shell session

It's not necessary to use this if you have `rtx activate` in your shell rc file.
Use this if you don't want to permanently install rtx.
This can be used similarly to `asdf shell`.
Unfortunately, it requires `eval` to work since it's not written in Bash though.
It's also useful just to see what environment variables rtx sets.

Usage: env [OPTIONS] [RUNTIME]...

Arguments:
  [RUNTIME]...
          runtime version to use

Options:
  -s, --shell <SHELL>
          Shell type to generate environment variables for
          
          [possible values: bash, fish, xonsh, zsh]

  -h, --help
          Print help (see a summary with '-h')


Examples:
  $ eval "$(rtx env -s bash)"
  $ eval "$(rtx env -s zsh)"
  $ rtx env -s fish | source
  $ execx($(rtx env -s xonsh))

rtx exec

execute a command with runtime(s) set

use this to avoid modifying the shell session or running ad-hoc commands with the rtx runtimes
set.

Runtimes will be loaded from .tool-versions, though they can be overridden with <RUNTIME> args
Note that only the plugin specified will be overriden, so if a `.tool-versions` file
includes "nodejs 20" but you run `rtx exec [email protected]`; it will still load nodejs@20.

The "--" separates runtimes from the commands to pass along to the subprocess.

Usage: exec [OPTIONS] [RUNTIME]... [-- <COMMAND>...]

Arguments:
  [RUNTIME]...
          runtime(s) to start
          
          e.g.: nodejs@20 [email protected]

  [COMMAND]...
          the command string to execute (same as --command)

Options:
  -c, --command <C>
          the command string to execute

  -h, --help
          Print help (see a summary with '-h')


Examples:
  rtx exec nodejs@20 -- node ./app.js  # launch app.js using node-20.x
  rtx x nodejs@20 -- node ./app.js     # shorter alias

Specify command as a string:
  rtx exec nodejs@20 [email protected] --command "node -v && python -V"

rtx global

sets global .tool-versions to include a specified runtime

this file is `$HOME/.tool-versions` by default
use `rtx local` to set a runtime version locally in the current directory

Usage: global [OPTIONS] [RUNTIME]...

Arguments:
  [RUNTIME]...
          runtimes
          
          e.g.: nodejs@20

Options:
      --fuzzy
          save fuzzy match to .tool-versions e.g.: `rtx global --fuzzy nodejs@20` will save `nodejs 20` to .tool-versions, by default, it would save the exact version, e.g.: `nodejs 20.0.0`

      --remove <PLUGIN>
          remove the plugin(s) from ~/.tool-versions

  -h, --help
          Print help (see a summary with '-h')


Examples:
  # set the current version of nodejs to 20.x
  # will use a precise version (e.g.: 20.0.0) in .tool-versions file
  $ rtx global nodejs@20     

  # set the current version of nodejs to 20.x
  # will use a fuzzy version (e.g.: 20) in .tool-versions file
  $ rtx global --fuzzy nodejs@20

rtx install

install a runtime

this will install a runtime to `~/.local/share/rtx/installs/<PLUGIN>/<VERSION>`
it won't be used simply by being installed, however.
For that, you must set up a `.tool-version` file manually or with `rtx local/global`.
Or you can call a runtime explicitly with `rtx exec <PLUGIN>@<VERSION> -- <COMMAND>`.

Usage: install [OPTIONS] [RUNTIME]...

Arguments:
  [RUNTIME]...
          runtime(s) to install
          
          e.g.: nodejs@20

Options:
  -p, --plugin <PLUGIN>
          only install runtime(s) for <PLUGIN>

  -f, --force
          force reinstall even if already installed

  -a, --all
          install all missing runtimes as well as all plugins for the current directory

  -v, --verbose...
          Show installation output

  -h, --help
          Print help (see a summary with '-h')


Examples:
  $ rtx install [email protected]  # install specific nodejs version
  $ rtx install nodejs@18      # install fuzzy nodejs version
  $ rtx install nodejs         # install latest nodejs version—or what is specified in .tool-versions
  $ rtx install                # installs all runtimes specified in .tool-versions for installed plugins
  $ rtx install --all          # installs all runtimes and all plugins

rtx latest

get the latest runtime version of a plugin's runtimes

Usage: latest <RUNTIME>

Arguments:
  <RUNTIME>
          Runtime to get the latest version of

Options:
  -h, --help
          Print help (see a summary with '-h')


Examples:
  $ rtx latest nodejs@18  # get the latest version of nodejs 18
  18.0.0
  
  $ rtx latest nodejs     # get the latest stable version of nodejs
  20.0.0

rtx local

Sets .tool-versions to include a specific runtime

use this to set the runtime version when within a directory
use `rtx global` to set a runtime version globally

Usage: local [OPTIONS] [RUNTIME]...

Arguments:
  [RUNTIME]...
          runtimes to add to .tool-versions
          
          e.g.: nodejs@20

Options:
  -p, --parent
          recurse up to find a .tool-versions file rather than using the current directory only by default this command will only set the runtime in the current directory ("$PWD/.tool-versions")

      --fuzzy
          save fuzzy match to .tool-versions e.g.: `rtx local --fuzzy nodejs@20` will save `nodejs 20` to .tool-versions by default it would save the exact version, e.g.: `nodejs 20.0.0`

      --remove <PLUGIN>
          remove the plugin(s) from .tool-versions

  -h, --help
          Print help (see a summary with '-h')


Examples:
  # set the current version of nodejs to 20.x for the current directory
  # will use a precise version (e.g.: 20.0.0) in .tool-versions file
  $ rtx local nodejs@20

  # set nodejs to 20.x for the current project (recurses up to find .tool-versions)
  $ rtx local -p nodejs@20

  # set the current version of nodejs to 20.x for the current directory
  # will use a fuzzy version (e.g.: 20) in .tool-versions file
  $ rtx local --fuzzy nodejs@20

  # removes nodejs from .tool-versions
  $ rtx local --remove=nodejs

rtx ls

list installed runtime versions

The "arrow (->)" indicates the runtime is installed, active, and will be used for running commands.
(Assuming `rtx activate` or `rtx env` is in use).

Usage: ls [OPTIONS]

Options:
  -p, --plugin <PLUGIN>
          Only show runtimes from [PLUGIN]

  -c, --current
          Only show runtimes currently specified in .tool-versions

  -h, --help
          Print help (see a summary with '-h')


Examples:
  $ rtx list
  -> nodejs     20.0.0 (set by ~/src/myapp/.tool-versions)
  -> python     3.11.0 (set by ~/.tool-versions)
     python     3.10.0
     
  $ rtx list --current
  -> nodejs     20.0.0 (set by ~/src/myapp/.tool-versions)
  -> python     3.11.0 (set by ~/.tool-versions)

rtx ls-remote

list runtime versions available for install

note that these versions are cached for commands like `rtx install nodejs@latest`
however _this_ command will always clear that cache and fetch the latest remote versions

Usage: ls-remote <PLUGIN>

Arguments:
  <PLUGIN>
          Plugin

Options:
  -h, --help
          Print help (see a summary with '-h')


Examples:
  $ rtx list-remote nodejs
  18.0.0
  20.0.0

rtx plugins install

install a plugin

note that rtx automatically can install plugins when you install a runtime
e.g.: `rtx install nodejs@18` will autoinstall the nodejs plugin

This behavior can be modified in ~/.rtx/config.toml

Usage: install [OPTIONS] [NAME] [GIT_URL]

Arguments:
  [NAME]
          The name of the plugin to install
          
          e.g.: nodejs, ruby

  [GIT_URL]
          The git url of the plugin
          
          e.g.: https://github.com/asdf-vm/asdf-nodejs.git

Options:
  -f, --force
          Reinstall even if plugin exists

  -a, --all
          Install all missing plugins
          
          This will only install plugins that have matching shortnames. i.e.: they don't need the full git repo url

  -v, --verbose...
          Show installation output

  -h, --help
          Print help (see a summary with '-h')


EXAMPLES:
    $ rtx install nodejs  # install the nodejs plugin using the shorthand repo:
                          # https://github.com/asdf-vm/asdf-plugins

    $ rtx install nodejs https://github.com/asdf-vm/asdf-nodejs.git
                          # install the nodejs plugin using the git url

    $ rtx install https://github.com/asdf-vm/asdf-nodejs.git
                          # install the nodejs plugin using the git url only
                          # (nodejs is inferred from the url)

rtx plugins ls

List installed plugins

Can also show remotely available plugins to install.

Usage: ls [OPTIONS]

Options:
  -a, --all
          list all available remote plugins
          
          same as `rtx plugins ls-remote`

  -u, --urls
          show the git url for each plugin
          
          e.g.: https://github.com/asdf-vm/asdf-nodejs.git

  -h, --help
          Print help (see a summary with '-h')

List installed plugins
Can also show remotely available plugins to install.

Examples:

  $ rtx plugins ls
  nodejs
  ruby
  
  $ rtx plugins ls --urls
  nodejs                        https://github.com/asdf-vm/asdf-nodejs.git
  ruby                          https://github.com/asdf-vm/asdf-ruby.git

rtx plugins ls-remote

List all available remote plugins

These are fetched from https://github.com/asdf-vm/asdf-plugins

Examples:
  $ rtx plugins ls-remote


Usage: ls-remote [OPTIONS]

Options:
  -u, --urls
          show the git url for each plugin
          
          e.g.: https://github.com/asdf-vm/asdf-nodejs.git

  -h, --help
          Print help (see a summary with '-h')

rtx plugins uninstall

removes a plugin

Usage: uninstall <PLUGIN>

Arguments:
  <PLUGIN>
          plugin to remove

Options:
  -h, --help
          Print help (see a summary with '-h')


Examples:
  $ rtx uninstall nodejs

rtx plugins update

updates a plugin to the latest version

note: this updates the plugin itself, not the runtime versions

Usage: update [OPTIONS] [PLUGIN]...

Arguments:
  [PLUGIN]...
          plugin(s) to update

Options:
  -a, --all
          update all plugins

  -h, --help
          Print help (see a summary with '-h')


Examples:
  rtx plugins update --all   # update all plugins
  rtx plugins update nodejs  # update only nodejs

rtx settings get

Show a current setting

This is the contents of a single entry in ~/.config/rtx/config.toml

Note that aliases are also stored in this file
but managed separately with `rtx aliases get`

Usage: get <KEY>

Arguments:
  <KEY>
          The setting to show

Options:
  -h, --help
          Print help (see a summary with '-h')

Examples:
  $ rtx settings get legacy_version_file
  true

rtx settings ls

Show current settings

This is the contents of ~/.config/rtx/config.toml

Note that aliases are also stored in this file
but managed separately with `rtx aliases`

Usage: ls

Options:
  -h, --help
          Print help (see a summary with '-h')

Examples:
  $ rtx settings
  legacy_version_file = false

rtx settings set

Add/update a setting

This modifies the contents of ~/.config/rtx/config.toml

Usage: set <KEY> <VALUE>

Arguments:
  <KEY>
          The setting to set

  <VALUE>
          The value to set

Options:
  -h, --help
          Print help (see a summary with '-h')

Examples:
  $ rtx settings set legacy_version_file true

rtx settings unset

Clears a setting

This modifies the contents of ~/.config/rtx/config.toml

Usage: unset <KEY>

Arguments:
  <KEY>
          The setting to remove

Options:
  -h, --help
          Print help (see a summary with '-h')

Examples:
  $ rtx settings unset legacy_version_file

rtx uninstall

removes runtime versions

Usage: uninstall <RUNTIME>...

Arguments:
  <RUNTIME>...
          runtime(s) to remove

Options:
  -h, --help
          Print help (see a summary with '-h')


Examples:
  $ rtx uninstall nodejs@18 # will uninstall ALL nodejs-18.x versions
  $ rtx uninstall nodejs    # will uninstall ALL nodejs versions

rtx version

Show rtx version

Usage: version

Options:
  -h, --help
          Print help

Comparison to asdf

rtx is mostly a clone of asdf, but there are notable areas where improvements have been made.

Performance

asdf made (what I consider) a poor design decision to use shims that go between a call to a runtime and the runtime itself. e.g.: when you call node it will call an asdf shim file ~/.asdf/shims/node, which then calls asdf exec, which then calls the correct version of node.

These shims have terrible performance, adding ~120ms to every runtime call. rtx does not use shims and instead updates PATH so that it doesn't have any overhead when simply calling binaries. These shims are the main reason that I wrote this.

I don't think it's possible for asdf to fix thse issues. The author of asdf did a great writeup of performance problems. asdf is written in bash which certainly makes it challening to be performant, however I think the real problem is the shim design. I don't think it's possible to fix that without a complete rewrite.

rtx does call an internal command rtx hook-env every time the directory has changed, but because it's written in Rust, this is very quick—taking ~10ms on my machine. 4ms if there are no changes, 14ms if it's a full reload.

tl;dr: asdf adds overhead (~120ms) when calling a runtime, rtx adds a small amount of overhead (~10ms) when the prompt loads.

Environment variables

asdf only helps manage runtime executables. However, some tools are managed via environment variables (notably Java which switches via JAVA_HOME). This isn't supported very well in asdf and requires a separate shell extension just to manage.

However asdf plugins have a bin/exec-env script that is used for exporting environment variables like JAVA_HOME. rtx simply exports the environment variables from the bin/exec-env script in the plugin but places them in the shell for all commands. In asdf it only exports those commands when the shim is called. This means if you call java it will set JAVA_HOME, but not if you call some Java tool like mvn.

This means we're just using the existing plugin script but because rtx doesn't use shims it can be used for more things. It would be trivial to make a plugin that exports arbitrary environment variables like dotenv or direnv.

UX

Some commands are the same in asdf but others have been changed. Everything that's possible in asdf should be possible in rtx but may use slighly different syntax. rtx has more forgiving commands, such as using fuzzy-matching, e.g.: rtx install nodejs@18. While in asdf you can run asdf install nodejs latest:18, you can't use latest:18 in a .tool-versions file or many other places. In rtx you can use fuzzy-matching everywhere.

asdf requires several steps to install a new runtime if the plugin isn't installed, e.g.:

$ asdf plugin add nodejs
$ asdf install nodejs latest:18
$ asdf local nodejs latest:18

In rtx this can all be done in a single step to set the local runtime version. If the plugin and/or runtime needs to be installed it will prompt:

$ asdf local nodejs@18
rtx: Would you like to install [email protected]? [Y/n] Y
Trying to update node-build... ok
Downloading node-v18.13.0-darwin-arm64.tar.gz...
-> https://nodejs.org/dist/v18.13.0/node-v18.13.0-darwin-arm64.tar.gz
Installing node-v18.13.0-darwin-arm64...
Installed node-v18.13.0-darwin-arm64 to /Users/jdx/.local/share/rtx/installs/nodejs/18.13.0
$ node -v
v18.13.0

I've found asdf to be particularly rigid and difficult to learn. It also made strange decisions like having asdf list all but asdf latest --all (why is one a flag and one a positional argument?). rtx makes heavy use of aliases so you don't need to remember if it's rtx plugin add nodejs or rtx plugin install nodejs. If I can guess what you meant, then I'll try to get rtx to respond in the right way.

That said, there are a lot of great things about asdf. It's the best multi-runtime manager out there and I've really been impressed with the plugin system. Most of the design decisions the authors made were very good. I really just have 2 complaints: the shims and the fact it's written in Bash.

direnv

direnv and rtx both manage environment variables based on directory. Because they both analyze the current environment variables before and after their respective "hook" commands are run, they can conflict with each other.

There were a number of issues with direnv. However, these should be resolved now and you should be able to use direnv alongside rtx.

If you do encounter issues, or just want to use direnv in an alternate way: there is a method of calling rtx from within direnv so you do not need to run rtx activate. This is a simpler setup that's less likely to cause issues.

To do this, first use rtx to build a use_rtx function that you can use in .envrc files:

$ rtx direnv activate > ~/.config/direnv/lib/use_rtx.sh
# replace ~/.config with XDG_CONFIG_HOME if you've changed it

Now in your .envrc file add the following:

use rtx

direnv will now call rtx to export its environment variables. You'll need to make sure to add use_rtx too all projects that use rtx (or use direnv's source_up to load it from a subdirectory). You can also add use rtx to ~/.config/direnv/direnvrc.

Note that in this method direnv typically won't know to refresh .tool-version files unless they're at the same level at a .envrc file. You'll likely always want to have a .envrc file next to your .tool-versions for this reason. To make this a little easier to manage, I encourage not actually using .tool-versions and instead setting environment variables entirely in .envrc:

export RTX_NODEJS_VERSION=18.0.0
export RTX_PYTHON_VERSION=3.11

Of course if you use rtx activate none of this is necesary.

Cache Behavior

rtx makes use of caching in many places in order to be efficient. The details about how long to keep cache for should eventually all be configurable. There may be gaps in the current behavior where things are hardcoded but I'm happy to add more settings to cover whatever config is needed.

Below I explain the behavior it uses around caching. If you're seeing behavior where things don't appear to be updating, this is a good place to start.

Shorthand Repository Cache

asdf maintains a shorthand repository which maps plugin short names (e.g.: nodejs) to full repository names (e.g.: https://github.com/asdf-vm/asdf-nodejs).

This is stored in ~/.local/share/rtx/repository and updated every week by default if short names are requested. This is similar to what asdf does, but I'm considering just baking this straight into the codebase so it doesn't have to be fetched/maintained separately. It's not like new plugins get added that often.

Plugin Cache

Each plugin has a cache that's stored in ~/.local/share/rtx/plugins/<PLUGIN>/.rtxcache.msgpack.gz. It stores the list of versions available for that plugin (rtx ls-remote <PLUGIN>) and the legacy filenames (see below).

It is updated daily by default or anytime that rtx ls-remote is called explicitly. The file is gzipped messagepack, if you want to view it you can run the following (requires msgpack-cli).

cat ~/.local/share/rtx/plugins/nodejs/.rtxcache.msgpack.gz | gunzip | msgpack-cli decode

Runtime Cache

Each runtime (language version, e.g.: [email protected]), has a file called "runtimeconf" that's stored inside the install directory, e.g.: ~/.asdf/installs/nodejs/20.0.0/.rtxconf.msgpack. This stores the information about the runtime that should not change after installation. Currently this is just the bin paths the plugin defines in bin/list-bin-paths. By default this is just /bin. It's the list of paths that rtx will add to PATH when the runtime is activated.

I have not seen a plugins which has dynamic bin paths but let me know if you find one. If that is the case, we may need to make this cached instead of static.

"Runtimeconf" is stored as uncompressed messagepack and can be viewed with the following:

cat ~/.local/share/rtx/installs/nodejs/18.13.0/.rtxconf.msgpack | msgpack-cli decode

Legacy File Cache

If enabled, rtx will read the legacy filenames such as .node-version for asdf-nodejs. This leverages cache in 2 places where the plugin is called:

  • list-legacy-filenames In every plugin I've seen this simply returns a static list of filenamed like ".nvmrc .node-version". It's cached alongside the standard "runtime" cache which is refreshed daily by default.
  • parse-legacy-file This plugin binary is called to parse a legacy file to get the version out of it. It's relatively expensive so every file that gets parsed as a legacy file is cached into ~/.local/share/rtx/legacy_cache. It will remain cached until the file is modified. This is a simple text file that has the path to the legacy file stored as a hash for the filename.

Development

Run tests with just:

$ just test

Lint the codebase with:

$ just lint-fix
Comments
  • rtx panics

    rtx panics

    I'm running rtx x [email protected] -- python3 -m venv . (version: rtx 1.5.0 (built 2023-02-04))in a bootstrap script (bash, calls more bash scripts which calls rtx; the main script exports some functions to make them available in the called additional bash scripts; not sure if the latter is interesting) and this ended up with:

    The application panicked (crashed).
    Message:  failed to set environment variable `""` to `""`: Invalid argument (os error 22)
    Location: library/std/src/env.rs:353
    
      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                    ⋮ 8 frames hidden ⋮
       9: std::env::_set_var::h6ff1976ef2d27892
          at <unknown source file>:<unknown line>
      10: <rtx::cli::exec::Exec as rtx::cli::command::Command>::run::h2d8bb112ad83bad8
          at <unknown source file>:<unknown line>
      11: rtx::cli::Cli::run::hd3b4bd09e4c19951
          at <unknown source file>:<unknown line>
      12: rtx::main::h346c180a454697a7
          at <unknown source file>:<unknown line>
      13: std::sys_common::backtrace::__rust_begin_short_backtrace::hd33f4d5347a9674e
          at <unknown source file>:<unknown line>
      14: std::rt::lang_start::{{closure}}::h7a55c4bdb7cc3632
          at <unknown source file>:<unknown line>
      15: std::rt::lang_start_internal::hd56d2fa7efb2dd60
          at <unknown source file>:<unknown line>
      16: _main<unknown>
          at <unknown source file>:<unknown line>
    
    Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
    Run with RUST_BACKTRACE=full to include source snippets.
    !!! ERROR !!! Script 8-py-venv-environments errored, aborting....
    

    Not sure if this is relevant, but for completeness:

    function exit_if_not_debian() {
      [[ "${YADM_BOOTSTRAP_DISTRO}" != 'debian' ]] && msg "Not Debian, Bye!" && exit
    }
    export -f exit_if_not_debian
    

    A exported function ends up as this when printed with env straight before the script:

    BASH_FUNC_exit_if_not_debian%%=() {  [[ "${YADM_BOOTSTRAP_DISTRO}" != 'debian' ]] && msg "Not Debian, Bye!" && exit
    }
    
    opened by jankatins 10
  • Unable to install older Java (x86_64) versions

    Unable to install older Java (x86_64) versions

    While asdf allowed to install older Java versions (compiled for x86_64) via arch, this seems not possible with rtx.

    ❯ arch -x86_64 rtx install [email protected]
    arch: posix_spawnp: rtx: Bad CPU type in executable
    

    As a workaround i manually downloaded the version and placed it in ~/.local/share/rtx/installs/java which seemed to work so far. Anything else to consider?

    opened by roele 7
  • rtxstatusln should output to stdout instead of stderr?

    rtxstatusln should output to stdout instead of stderr?

    Was chasing some weird bug in my added xonsh support module and realized that rtxstatusln prints non-quiet messages like rtx: [email protected] to stderr instead of stdout, and I had a condition that if you hook-env command has an error in a captured subprocess, then the stdout shouldn't be passed to the shell for execution.

    Is there a reason why status messages are printed as errors?

    https://github.com/jdxcode/rtx/blob/f0dc795c84ef20b6ba042fa77cef6adc3a79a129/src/cli/hook_env.rs#L84-L85

    https://github.com/jdxcode/rtx/blob/f0dc795c84ef20b6ba042fa77cef6adc3a79a129/src/output.rs#L94-L95

    opened by eugenesvk 7
  • Issue #71 - use positional arguments for activate

    Issue #71 - use positional arguments for activate

    "rtx activate " now works. Old behavior is kept as well (with -s/--shell flag) but it is not advertised in --help or in README.

    @jdxcode I thought I would give #71 a try. Please take a look if this is what you had in mind.

    In addition to activate, I changed deactivate as well, to keep it symmetrical. One more place where I noticed --shell is for env command. I did not touch that one, but I can if you prefer positional args there as well. It did not feel natural to me, since it already has runtime Vec as parameter.

    Any feedback is welcome, I actually looked at Rust code for the first time with rtx, so I am sure I did something wrong.

    opened by delicb 6
  • Setting of asdf-plugin environment variables inconsistent

    Setting of asdf-plugin environment variables inconsistent

    I tested the environment variables a bit more using rtx 1.2.6 and found some unexpected behavior while using them.

    Using eval "$(rtx activate -s zsh)" in a new zsh session (no direnv):

    1. All environment variables unset/empty, when switching to a new directory without .tool-versions
    # initially all environment variables are set as expected
    ❯ echo $RUBYLIB
    /Users/user/.local/share/rtx/plugins/ruby/rubygems-plugin
    ❯ echo $GOROOT
    /Users/user/.local/share/rtx/installs/golang/1.19.5/go
    ❯ echo $JAVA_HOME
    /Users/user/.local/share/rtx/installs/java/temurin-17.0.5+8
    
    # Issue: All environment variables unset/empty, when switching to a new directory
    # Expected: All environment variables have the same value as above
    # `~/dev` doesn't contain a .tool-versions file
    
    ❯ cd ~/dev
    ❯ echo $RUBYLIB
    
    ❯ echo $JAVA_HOME
    
    ❯ echo $GOROOT
    
    
    1. RUBYLIB unset in directory containing a local .tool-versions file -> This might be no real issues with rtx, as RUBYLIB seems to contain only a file needed for asdf related reshimming, when installing a rubygem file with an executable. But perhaps it is still relevant to understand the behavior.
    # initially all environment variables are set as expected
    ❯ echo $GOROOT
    /Users/user/.local/share/rtx/installs/golang/1.19.5/go
    ❯ echo $JAVA_HOME
    /Users/user/.local/share/rtx/installs/java/temurin-17.0.5+8
    ❯ echo $RUBYLIB
    /Users/user/.local/share/rtx/plugins/ruby/rubygems-plugin
    
    # switching directory
    
    ❯ cd ~/dev/tmp/rtx-env-variables
    ❯ cat .tool-versions
    java temurin-11.0.15+10
    golang 1.18.1
    ruby 3.0.5
    
    # all environment variables besides RUBYLIB set to new values. RUBYLIB is unset. Not sure, if this is on purpose the same in asdf.
    # Expected: RUBYLIB still set (?)
    
    ❯ echo $GOROOT
    /Users/user/.local/share/rtx/installs/golang/1.18.10/go
    ❯ echo $JAVA_HOME
    /Users/user/.local/share/rtx/installs/java/temurin-11.0.15+10
    ❯ echo $RUBYLIB
    
    # again, when traversing to a subdirectory all environment variables are unset. But this time RUBYLIB is unexpectedly set now
    # Expected: All environment variables set to the values of nearest local .tool-versions
    
    ❯ mkdir test
    ❯ cd test
    ❯ echo $GOROOT
    
    ❯ echo $JAVA_HOME
    
    ❯ echo $RUBYLIB
    /Users/user/.local/share/rtx/plugins/ruby/rubygems-plugin
    
    # for completeness, the value when switching back to the previous directory
    
    ❯ cd ..
    ❯ echo $GOROOT
    /Users/user/.local/share/rtx/installs/golang/1.18.10/go
    ❯ echo $JAVA_HOME
    /Users/user/.local/share/rtx/installs/java/temurin-11.0.15+10
    ❯ echo $RUBYLIB
    
    

    Using eval "$(rtx env -s zsh)" in a new zsh session in combination with use rtx in direnv:

    1. GOROOT not updated and RUBYLIB concatenated to incorrect value
    # initially all environment variables are set as expected
    
    ❯ echo $GOROOT
    /Users/user/.local/share/rtx/installs/golang/1.19.5/go
    ❯ echo $JAVA_HOME
    /Users/user/.local/share/rtx/installs/java/temurin-17.0.5+8
    ❯ echo $RUBYLIB
    /Users/user/.local/share/rtx/plugins/ruby/rubygems-plugin
    
    # switching to a project folder managed by direnv
    
    ❯ cd ~/dev/tmp/rtx-env-variables-direnv
    direnv: loading ~/Projects/tmp/rtx-env-variables-direnv/.envrc
    direnv: using rtx
    direnv: export ~JAVA_HOME ~PATH ~RUBYLIB
    
    # Expected: GOROOT set to 1.18.1 and not unchanged
    # Is set correctly for JAVA_HOME
    
    ❯ echo $GOROOT
    /Users/user/.local/share/rtx/installs/golang/1.19.5/go
    ❯ echo $JAVA_HOME
    /Users/user/.local/share/rtx/installs/java/temurin-11.0.15+10
    
    # Expected: RUBYLIB value set to `/Users/user/.local/share/rtx/plugins/ruby/rubygems-plugin` and not concatenated
    
    ❯ echo $RUBYLIB
    /Users/user/.local/share/rtx/plugins/ruby/rubygems-plugin:/Users/user/.local/share/rtx/plugins/ruby/rubygems-plugin
    
    # folder setup
    
    ❯ cat .envrc
    use rtx
    
    ❯ cat .tool-versions
    java temurin-11.0.15+10
    golang 1.18.1
    ruby 3.0.5
    
    ❯ rtx local
    java temurin-11.0.15+10
    golang 1.18.1
    ruby 3.0.5
    ❯ go version
    go version go1.18.10 darwin/arm64
    ❯ java --version
    openjdk 11.0.15 2022-04-19
    OpenJDK Runtime Environment Temurin-11.0.15+10 (build 11.0.15+10)
    OpenJDK 64-Bit Server VM Temurin-11.0.15+10 (build 11.0.15+10, mixed mode)
    ❯ ruby --version
    ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c5) [arm64-darwin22]
    
    bug 
    opened by amoosbr 6
  • [feat] add Xonsh shell support

    [feat] add Xonsh shell support

    Seems to be working (it compiles, and since it's Rust, should be fine :)), installed a tool and check entering/exiting a dir with a .tool-versions file, did all the contributing list of checks (though hate that the all the linters hate properly aligned code and turn ↓ tabular beauty into a ziz-zagged mess

    Some(escaped_char) => escaped_string.push_str(escaped_char),
    None               => escaped_string.push(ch), // ← cleaner to see the diff vs ↓
    
    Some(escaped_char) => escaped_string.push_str(escaped_char),
    None => escaped_string.push(ch),
    

    )

    Meanwhile, a few questions/comments:

    • var name: I've changed the escape rules for variable values (xonsh uses Python escape rules, not unix shell's), but NOT for variable names — escapes in $KEY_VAR_with_weird_chars won't help, it will still result in an error as it's considered an identifier. Don't think anyone would use weird names in variables, but even if they would I think erroring out would be correct as I'm not sure the plugin would expect a silent rename? For now, don't plan to add any fix (and anyway Python has a bunch of identifier rules defined as unicode char groups with some legacy exceptions etc, so didn't want to recreate them from scratch either, do you maybe know a crate that does that?)
    • perf: There is a chance to eek out a ~15% performance on execution when cd-ing into a new dir with a .tool-versions file (maybe a bit more on new empty dir, but the base is much smaller there), but then you lose autocolor detection (user's would need to use $FORCE_COLOR env var to get it back). Worth it?
    • path: I see that you replace the whole $PATH every time. This might have a slight negative affect on user configs who have shell $PATH different from OS environment PATH for one reason or another since both are currently overwritten with values from rtx (shell PATH needs to be overwritten to find rtx and other executables, OS PATH needs to be overwritte since that's where rtx reads info from). Meanwhile, xonsh is capable of adding/removing individual items to/from a $PATH. Is this something that rtx could pass instead of the wholesale replacement of PATH (afaik you're moving to more granular tracking approach anyway due to a conflict with direnv)?
    opened by eugenesvk 5
  • When exactly should rtx be hooked into in a shell

    When exactly should rtx be hooked into in a shell

    upd: the docs mean on every prompt redraw, not shell launch, and fish implementation is consistent with that (it has some extra hooks to account for the arrow-cd functionality that doesn't redraw the prompt, but still doesn't refresh on every command)

    I've updated rtx to work with this great Python-powered, cross-platform, Unix-gazing shell https://github.com/xonsh/xonsh (will send a PR eventually) and when converting the hook functions noticed differences between fish/bash, and then got a bit confused, so need some clarification

    Your Readme suggests that there should only be two hook events

    • on shell launch (makes sense, before any cd you still need to check the cwd)
    • on cd (makes sense, every new cwd can have a different environment)

    rtx installs as a shell extension (e.g. rtx activate -s zsh) that sets the PATH environment variable to point your shell to the correct runtime binaries. When you cd into a directory containing a .tool-versions file, rtx will automatically activate the correct versions. Every time your prompt starts it will call rtx hook-env to fetch new environment variables. This should be very fast and it exits early if the the directory wasn't changed or the .tool-version files haven't been updated. On my machine this takes 1-2ms even if it doesn't exit early.

    But then zsh has two hooks in activate functions

    • chpwd_functions on cd
    • precmd_functions before every command
    • no 3rd hook on shell launch, but I guess you don't need to do anything on shell launch if you don't execute any commands?

    Bash has one in an activate function

    • if ! [[ "${PROMPT_COMMAND:-}" =~ _rtx_hook ]] on every command?
    • also no hook on launch?

    Fish is a bit more complicated

    • fish_prompt on every prompt, but within and then an extra check for cd depending on user config
    • fish_preexec before every command, but also depends on user config The hook on launch comes from fish_prompt, I guess

    Xonsh allows more granularity than the shells above (before/after prompt, before/after command, on cd), so I'm just trying to understand what the minimum viable set of hooks should be

    So a few questions:

    • why do you need to hook every single command execution, is cd+launch from the Readme not enough?
    • why do you need any hooks on cd if you already hook into every command?
    • why do you need to update on every prompt (fish) even after launch without any commands/cd (so I guess every hit of Enter on an emtpy line updates?)

    Thanks for any clarification!

    opened by eugenesvk 5
  • PATH update behavior by rtx hooks

    PATH update behavior by rtx hooks

    I created this as a separate issue, as this might be working as expected, be a more complex discussion, or a complicated change. I look here especially at PATH, but it might be similar for other environment variables set by plugins. For this example, I use eval "$(rtx activate -s zsh)" without direnv.

    Issue: A manually customized PATH will be overwritten, when switching directories. Expected: Only updated the PATH if necessary and in a "expected way".

    Current behavior:

    ❯ echo $PATH
    /Users/user/.local/share/rtx/installs/python/3.10.9/bin:...
    ❯ export PATH="$HOME/bin:${PATH}"
    ❯ echo $PATH
    /Users/user/bin:/Users/user/.local/share/rtx/installs/python/3.10.9/bin:...
    
    # switch to a directory not containing a local .tool-versions config
    ❯ cd dev
    
    # expected: no change of PATH
    # but customized PATH is overwritten and my custom added PATH value gone
    
    ❯ echo $PATH
    /Users/user/.local/share/rtx/installs/python/3.10.9/bin:...
    

    "Expected" behavior:

    1. zsh load -> add global tool version bin paths to PATH
      1. on directory change, new directory has no local .tool-versions: instead of an overwrite (as is done today?), don't update/set PATH
        1. would fix a custom extended PATH being overwritten by rtx
      2. on directory change, new directory has local .tool-versions: "in place" update of rtx bin paths as needed according to local .tool-versions
        1. "in-place" update would allow keeping custom changes and order of PATH

    I don't know, if this "expected" behavior is just my personal preference or expected by a majority of users. I can also not tell, if this is possible with rtx or if it would require using shims. Something you wanted to avoid with rtx.

    For me, a valid alternative way forward, is probably to not use eval "$(rtx activate -s zsh)", but direnv in combination with an initial global PATH setup via eval "$(rtx env -s zsh)".

    But wanted to mention this and open it for comments.

    bug 
    opened by amoosbr 5
  • Brew install method requires Github credentials?

    Brew install method requires Github credentials?

    When I use the Homebrew install method on MacOS, it prompts me for my Github credentials. Is this expected?

    ❯ brew install jdxcode/tap/rtx
    ==> Tapping jdxcode/tap
    Cloning into '/opt/homebrew/Library/Taps/jdxcode/homebrew-tap'...
    Username for 'https://github.com':
    
    opened by blopker 5
  • Ruby plugin adds file that attempts to reshim - Error if asdf is not installed

    Ruby plugin adds file that attempts to reshim - Error if asdf is not installed

    The Ruby plugin tries to reshim on each gem install.

    https://github.com/asdf-vm/asdf-ruby/blob/master/rubygems-plugin/rubygems_plugin.rb

    Leading to this error:

    ERROR:  While executing gem ... (Errno::ENOENT)
        No such file or directory - asdf
            ~/.local/share/rtx/plugins/ruby/rubygems-plugin/rubygems_plugin.rb:15:in ``'
            ~/.local/share/rtx/plugins/ruby/rubygems-plugin/rubygems_plugin.rb:15:in `block (2 levels) in <top (required)>'
            ~/.local/share/rtx/plugins/ruby/rubygems-plugin/rubygems_plugin.rb:14:in `each'
            ~/.local/share/rtx/plugins/ruby/rubygems-plugin/rubygems_plugin.rb:14:in `block in <top (required)>'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/installer.rb:381:in `block in run_post_install_hooks'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/installer.rb:380:in `each'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/installer.rb:380:in `run_post_install_hooks'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/installer.rb:345:in `install'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/resolver/specification.rb:104:in `install'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/request_set.rb:194:in `block in install'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/request_set.rb:182:in `each'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/request_set.rb:182:in `install'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/commands/install_command.rb:214:in `install_gem'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/commands/install_command.rb:230:in `block in install_gems'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/commands/install_command.rb:223:in `each'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/commands/install_command.rb:223:in `install_gems'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/commands/install_command.rb:169:in `execute'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/command.rb:323:in `invoke_with_build_args'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/command_manager.rb:185:in `process_args'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/command_manager.rb:149:in `run'
            ~/.local/share/rtx/installs/ruby/3.2.0/lib/ruby/3.2.0/rubygems/gem_runner.rb:51:in `run'
    

    I "fixed" the problem by deleting the rubygems_plugin.rb file entirely. But I'm curious if it'd be possible to have an alias for asdf that no-ops these functions.

    Apologies if this is a duplicate, I looked around and didn't see anything related exactly to this.

    opened by wmbest2 4
  • Feature request: command to get path to selected runtime

    Feature request: command to get path to selected runtime

    It would be great to be able to obtain path to single runtime as command, same value that is being injected to $PATH.

    My use case is that I want to set pipx to use currently selected Python. With asdf in Fish, I use set -gx PIPX_DEFAULT_PYTHON "$HOME/.asdf/shims/python", but since rtx does not use shims, there is no "stable" path to use here.

    I imagine solution like: set -gx PIPX_DEFAULT_PYTHON (rtx runtime-path python)/python

    where rtx runtime-path python (or whatever command name, I don't have a preference here) would return the same path as is injected to $PATH (e.g. $HOME/.local/share/rtx/installs/python/3.11.1/bin).

    If there is other solution for this use case, I have not figured it out and would like to hear about it.

    btw, thanks for a great tool, creating and open-sourcing it, looking forward to using it actively :)

    opened by delicb 4
  • Don't show default activated version on shell startup

    Don't show default activated version on shell startup

    rtx prints the versions which get activated per default (`~/.tool-version) when I open my shell. Is there a way to prevent that and only print when I change away from it (or back to it)?

    opened by jankatins 7
  • `rtx version` not working if config loading fails

    `rtx version` not working if config loading fails

    this might be a hard one to fix but in the case where config loading errors out it won't be able to display the version:

    $ rtx version
    Error:
       0: [python] script exited with non-zero status: no exit status
       1: No such file or directory (os error 2)
    
    Location:
       src/plugins/script_manager.rs:150
    
    Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
    Run with RUST_BACKTRACE=full to include source snippets.
    

    We should harden this case so people can figure out what version rtx is even if their setup isn't working. An acceptable workaround may be to simply display the version in the error output.

    opened by jdxcode 0
  • `rtx doctor` improvements

    `rtx doctor` improvements

    if users report a problem, we should have them run rtx doctor first and display the output.

    Some things this should probably display:

    • [ ] rtx version
    • [ ] rtx os/arch
    • [ ] rust version used to compile the build
    • [ ] operating system version? not sure how easy this is to get but might be good to have
    • [ ] current shell and version
    • [ ] RTX environment variables
    • [ ] RTX settings
    • [ ] active tool-version and legacy version files
    • [ ] active plugins with repo url and git sha (maybe denote if these are old/out of date somehow)
    • [ ] active runtimes
    • [ ] add rtx doctor instructions to GH issue template
    enhancement good first issue 
    opened by jdxcode 0
  • completions should complete plugins + versions

    completions should complete plugins + versions

    the completions right now only help complete things like command names and option names. Ideally you should be able to complete with something like this:

    rtx install nodejs@18<tab><tab>
    rtx install nodejs@<tab><tab>
    rtx install nod<tab><tab>
    

    This probably is non-trivial, but it would certainly be nice.

    help wanted 
    opened by jdxcode 0
  • E2E tests not tracked by codecov

    E2E tests not tracked by codecov

    Only the unit tests are counted for code coverage data. We should include E2E tests as part of that analysis.

    Unfortunately this isn't trivial the way things are setup. The E2E test currently use a full-fledged release binary that is exactly what will be published as the release. In order to add coverage support we would need to use a separate binary that has coverage enabled on it.

    I think the right solution is to actually run the E2E tests twice (they take less than a minute so it's no big deal). This is actually probably a good idea anyways because E2E tests could behave differently when run a second time since the plugins and runtimes all would exist. We would run it once for coverage, and once against the release build.

    testing 
    opened by jdxcode 0
Releases(v1.5.1)
Owner
Jeff Dickey
Engineer @aws. Formerly Lead Engineer of @heroku CLI and @oclif
Jeff Dickey
A simple, cross-platform GUI automation module for Rust.

AutoPilot AutoPilot is a Rust port of the Python C extension AutoPy, a simple, cross-platform GUI automation library for Python. For more information,

null 271 Dec 27, 2022
A data-first Rust-native UI design toolkit.

Druid A data-first Rust-native UI toolkit. Druid is an experimental Rust-native UI toolkit. Its main goal is to offer a polished user experience. Ther

null 8.2k Dec 31, 2022
The Rust UI-Toolkit.

The Orbital Widget Toolkit is a cross-platform (G)UI toolkit for building scalable user interfaces with the programming language Rust. It's based on t

Redox OS 3.7k Jan 1, 2023
An easy-to-use, 2D GUI library written entirely in Rust.

Conrod An easy-to-use, 2D GUI library written entirely in Rust. Guide What is Conrod? A Brief Summary Screenshots and Videos Feature Overview Availabl

PistonDevelopers 3.3k Jan 1, 2023
Rust bindings to Core Foundation and other low level libraries on Mac OS X and iOS

core-foundation-rs Compatibility Targets macOS 10.7 by default. To enable features added in macOS 10.8, set Cargo feature mac_os_10_8_features. To hav

Servo 685 Jan 2, 2023
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The FLTK crate is a crossplatform lightweight gui library which can be statically

Mohammed Alyousef 1.1k Jan 9, 2023
Build beautiful desktop apps with flutter and rust. 🌠 (wip)

flutter-rs Build flutter desktop app in dart & rust. Get Started Install requirements Rust flutter sdk Develop install the cargo flutter command cargo

null 2k Dec 26, 2022
Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust

Relm Asynchronous, GTK+-based, GUI library, inspired by Elm, written in Rust. This library is in beta stage: it has not been thoroughly tested and its

null 2.2k Dec 31, 2022
Rust bindings for Dear ImGui

imgui-rs: Rust bindings for Dear ImGui (Recently under new maintenance, things subject to change) Window::new(im_str!("Hello world")) .size([300.0

null 2k Jan 7, 2023
Clear Coat is a Rust wrapper for the IUP GUI library.

Clear Coat Clear Coat is a Rust wrapper for the IUP GUI library. IUP uses native controls and has Windows and GTK backends. A macOS backend has been o

Jordan Miner 18 Feb 13, 2021
Rust binding for IUP

IUP Rust This library provides a high level wrapper around IUP, a multi-platform toolkit for building graphical user interfaces. See rust-iup-sys for

David Campbell 41 May 28, 2022
A simple UI framework for Rust built on top of IUP (http://webserver2.tecgraf.puc-rio.br/iup/)

KISS-UI A UI framework for Rust based on the KISS (Keep It Simple, Stupid!) philosophy. Powered by the IUP GUI library for C by Tecgraf, via the bindi

null 342 Jul 11, 2022
Rust bindings to the minimalist, native, cross-platform UI toolkit `libui`

Improved User Interface A cross-platform UI toolkit for Rust based on libui iui: ui-sys: iui is a simple (about 4 kLOC of Rust), small (about 800kb, i

Rust Native UI Group 865 Dec 27, 2022
Integrate Qml and Rust by building the QMetaObject at compile time.

QMetaObject crate for Rust The qmetaobject crate is a crate which is used to expose rust object to Qt and QML. Objectives Rust procedural macro (custo

Woboq GmbH 495 Jan 3, 2023
QtQuick interface for Rust

qmlrs - QtQuick bindings for Rust qmlrs allows the use of QML/QtQuick code from Rust, specifically Rust code can create a QtQuick engine (QQmlApplicat

Mikko Perttunen 432 Nov 24, 2022
Qt5 binding for rust language. (stalled)

Qt5 binding for Rust language. qt.rs This project provides bindings that allow the QT Gui toolkit to be used from the Rust Programming language. Compi

yatsen1 37 Oct 12, 2021
QML (Qt Quick) bindings for Rust language

QML-rust - bindings for Qt Quick Bindings are based on DOtherSide C bindings for QML Library is mostly feature-compliant with other bindings based on

Oak 204 Dec 8, 2022
Rust bindings for Sciter

Rust bindings for Sciter Check this page for other language bindings (Delphi / D / Go / .NET / Python / Rust). Introduction Sciter is an embeddable mu

Terra Informatica Software, Inc 757 Dec 30, 2022
A cross-platform GUI library for Rust, inspired by Elm

Iced A cross-platform GUI library for Rust focused on simplicity and type-safety. Inspired by Elm. Features Simple, easy-to-use, batteries-included AP

Héctor Ramón 17.5k Jan 2, 2023