RUSH_ENV(1)

NAME

rush_env - import environment updates from standard input.

SYNOPSIS

rush_env import-json
rush_env import-sh

DESCRIPTION

rush_env import-json reads standard input as a JSON object and applies the object to the current shell environment. String values set and export variables. null values unset variables. Other JSON values are rejected.

rush_env import-sh reads a narrow Bash-style environment script from standard input: export NAME=value lines set and export variables, and unset NAME lines unset variables. Any other command syntax is rejected instead of evaluated.

Imported names must be valid shell variable names. This keeps imported state representable as normal Rush shell variables.

EXAMPLE

Rush ships autoloaded rush_direnv_hook and rush_mise_hook helpers using this pattern. The definitions below show what those helpers do.

rush_direnv_hook() {
  if ! command -v direnv >/dev/null 2>&1; then
    return 0
  fi
  output="$(direnv export json)" || return $?
  rush_env import-json <<EOF
$output
EOF
}

event add directory.change direnv rush_direnv_hook
rush_mise_hook() {
  if ! command -v mise >/dev/null 2>&1; then
    return 0
  fi
  output="$(mise hook-env -s bash --quiet)" || return $?
  rush_env import-sh <<EOF
$output
EOF
}

event add directory.change mise rush_mise_hook

EXIT STATUS

Zero when the environment is applied, one for invalid environment input, and two for usage errors.

SEE ALSO

rush-builtins(7), event(1), rush configuration.