Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ These variables offer key information about the current environment:
- `config_root: PathBuf` – Locates the directory containing your `mise.toml` file, or in the case of something like `~/src/myproj/.config/mise.toml`, it will point to `~/src/myproj`.
- `mise_bin: String` - Points to the path to the current mise executable
- `mise_pid: String` - Points to the pid of the current mise process
- `mise_env: String` - The configuration environment as specified by `MISE_ENV`, `-E`, or `--env`. Will be undefined if the configuration environment is not set.
- `xdg_cache_home: PathBuf` - Points to the directory of XDG cache home
- `xdg_config_home: PathBuf` - Points to the directory of XDG config home
- `xdg_data_home: PathBuf` - Points to the directory of XDG data home
Expand Down
10 changes: 10 additions & 0 deletions e2e/env/test_env_profiles
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ echo 'env.AAA = "override-2"' >mise.override2.toml
assert "mise env --json | jq -r .AAA" "main"
MISE_ENV=override1 assert "mise env --json | jq -r .AAA" "override-1"
MISE_ENV=override1,override2 assert "mise env --json | jq -r .AAA" "override-2"

cat <<EOF >mise.toml
[tasks.print]
run = '{% if mise_env %}echo {{mise_env}}{% endif %}'
EOF
assert "mise run print" ""
MISE_ENV=env1 assert "mise run print" "[env1]"
MISE_ENV=env1,env2 assert "mise run print" "[env1, env2]"
assert "mise --env env3 run print" "[env3]"
assert "mise -E env3,env4 run print" "[env3, env4]"
8 changes: 8 additions & 0 deletions src/tera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub static BASE_CONTEXT: Lazy<Context> = Lazy::new(|| {
context.insert("env", &*env::PRISTINE_ENV);
context.insert("mise_bin", &*env::MISE_BIN);
context.insert("mise_pid", &*env::MISE_PID);
if !(*env::MISE_ENV).is_empty() {
context.insert("mise_env", &*env::MISE_ENV);
}
if let Ok(dir) = env::current_dir() {
context.insert("cwd", &dir);
}
Expand Down Expand Up @@ -381,6 +384,11 @@ mod tests {
assert_eq!(render("{{config_root}}"), "/");
}

#[test]
fn test_mise_env() {
assert_eq!(render("{% if mise_env %}{{mise_env}}{% endif %}"), "");
}

#[test]
fn test_cwd() {
assert_eq!(render("{{cwd}}"), "/");
Expand Down