#development #environment

bin+lib rsenv

Hierarchical environment variable management

8 releases (5 breaking)

0.13.2 Sep 26, 2023
0.13.0 Sep 15, 2023
0.11.0 Sep 15, 2023
0.10.1 Sep 9, 2023
0.1.0 Aug 14, 2023

#3 in #development-environment

Download history 16/week @ 2023-10-29 3/week @ 2023-11-12 17/week @ 2023-11-19 34/week @ 2023-11-26 8/week @ 2023-12-03 8/week @ 2023-12-10 16/week @ 2023-12-24 1/week @ 2024-01-07 1/week @ 2024-01-21 17/week @ 2024-01-28 1/week @ 2024-02-04 36/week @ 2024-02-11

55 downloads per month

BSD-3-Clause

69KB
1.5K SLoC

rs-env

Blog: Hierarchical environment variable management

Features

  • Compile resulting set of from a hierarchical list of <name>.env files.
  • Dependencies can form a tree or DAG (directed acyclic graph).
  • Last defined variable wins, i.e. child tops parent, rightmost sibling tops left sibling (in case of DAG).
  • Smart environment selection via builtin FZF (fuzzy find).
  • Quick edit via builtin FZF.
  • Side-by-side Tree edit.
  • direnv integration: Have the resulting variable list written to your .envrc file.
  • JetBrains integration via EnvFile plugin.

Concept

concept

Installation

cargo install rs-env

Usage

The resulting set of environment variables is an amalgamation of all files involved in the dependency tree, parent variables are overwritten by child variables.

  • DAG: Directed acyclic graph, i.e. files can have multiple parents
  • branch: a linear list of files, each file can have one parent (no DAG).
  • tree: a collection of branches (files can be part of multiple branches, but only one parent)
  • environment variables are defined in files <name>.env and must be prefixed with export command
  • See examples for DAG, Tree and Branches
  • multiple trees/branches per project are supported
  • files are linked either manually by adding the comment line # rsenv: <name.env> or via the command: rsenv link <root.env> <child1>.env <child2>.env.

Source the resulting set of variables as usual:

source <(rsenv build <leaf-node.env>)
Hierarchical environment variable management

Usage: rsenv [OPTIONS] [NAME] [COMMAND]

Commands:
  build        Build the resulting set of environment variables (DAG/Tree)
  envrc        Write the resulting set of variables to .envrc (requires direnv, DAG/Tree)
  files        Show all files involved in resulting set (DAG/Tree)
  edit-leaf    Edit the given environment file and all its parents (DAG/Tree)
  edit         Edit the FZF selected branch/DAG
  select-leaf  select environment/branch and update .envrc file (requires direnv, DAG/Tree)
  select       FZF based selection of environment/branch and update of .envrc file (requires direnv, DAG/Tree)
  link         Link files into a linear dependency branch (root -> parent -> child)
  branches     Show all branches (linear representation)
  tree         Show all trees (hierarchical representation)
  tree-edit    Edit branches of all trees side-by-side (vim required in path)
  leaves       Output leaves as paths (Tree)
  help         Print this message or the help of the given subcommand(s)

Arguments:
  [NAME]  Optional name to operate on

Options:
  -d, --debug...              Turn debugging information on
      --generate <GENERATOR>  [possible values: bash, elvish, fish, powershell, zsh]
      --info                  
  -h, --help                  Print help
  -V, --version               Print version

Basic


Select via FZF


Tree and Branch structure (Smart edit)


Integrations

direnv

direnv activates environments automatically.

  • rs-env can update the .envrc file with the selected dependency graph variables.

JetBrains Integration

Life injection of environment variables:

  • Plugin EnvFile can be used to life-inject environment variables.
  • Use the script runenv.sh as the "EnvFile" script (tick executable checkbox !).
  • The environment variable RUN_ENV parametrizes which environment to load.
  • It will look for a file <RUN_ENV>.env in the specified directory.

jetbrain

Development

  • Tests for "skim" need valid terminal, so they are run via Makefile.
  • Test for rsenv select: run debug target and check rsenv .envrc file.

Dependencies

~15–28MB
~421K SLoC