xx
.md

env_append

env_append returns a dependency that adds one item to the end of an environment variable. Items are joined with the host path-list separator, making the function suitable for PATH and similar variables.

Arguments

ArgumentRequiredDescription
keyYesEnvironment variable name to change.
valueYesString item to append.
uniqueNoKeep the existing value when an equivalent item is already present. Defaults to False.

Uniqueness uses exact string comparison on Linux and macOS. On Windows, PATH entries are compared case-insensitively; other variables use exact comparison.

Examples

Append one search path

load("@os@1", "env_append", "run")

run(
    ("project-linter", "check"),
    deps=[env_append("PATH", "tools/bin")],
)

Avoid duplicate entries

load("@os@1", "env_append", "run")

tool_paths = (
    env_append("PATH", "tools/bin", unique=True) +
    env_append("PATH", "vendor/bin", unique=True)
)

run(("project-linter", "check"), deps=[tool_paths])