1 unstable release
Uses new Rust 2024
new 0.1.0 | May 8, 2025 |
---|
#403 in #error
Used in boxunbox
13KB
192 lines
expandenv-rs
A Rust crate for expanding environment variables, inspired by shellexpand.
This might not be very feature complete because I made it for a CLI tool of mine called boxunbox, but I figured someone else might also find some use because shellexpand
is now unmaintained.
lib.rs
:
This crate is for expanding environment variables and tilde's (~
) with support for fallback
values.
Examples
#
#
#
#
// expand a variable
let envvar_value = expand("$FOO")?;
// return an error if it fails
assert!(expand("$MISSING_VAR").is_err());
// or expand a fallback on failure
let envvar_value = expand("${MISSING_VAR:-$FOO}")?;
// you can even expand an entire path!
// the `~` expands to your home directory
let path = expand("~/${MISSING_VAR:-$FOO}/file.txt")?;
#
Dependencies
~2.4–4.5MB
~76K SLoC