diff options
author | Denis Isidoro <denisidoro@users.noreply.github.com> | 2021-01-13 09:17:37 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-13 09:17:37 -0300 |
commit | dd51959817ab12a1af7f3993edc0db94a3239c96 (patch) | |
tree | 2f8a216c90b339213e32f28c0d7f858f288a3fbf | |
parent | 5c43c5173a89589b7017de5945d493d00c1a4e9b (diff) |
Convert - to _ when reading env vars (#454)
-rw-r--r-- | src/cmds/core.rs | 5 | ||||
-rw-r--r-- | src/display/terminal.rs | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/cmds/core.rs b/src/cmds/core.rs index 9b5f772..66cd81c 100644 --- a/src/cmds/core.rs +++ b/src/cmds/core.rs @@ -198,7 +198,8 @@ fn replace_variables_from_snippet( for bracketed_variable_name in variables_found { let variable_name = &bracketed_variable_name[1..bracketed_variable_name.len() - 1]; - let env_value = env::var(variable_name); + let env_variable_name = variable_name.replace('-', "_"); + let env_value = env::var(&env_variable_name); let value = if let Ok(e) = env_value { e @@ -211,7 +212,7 @@ fn replace_variables_from_snippet( prompt_finder(variable_name, &config, None, variable_count)? }; - env::set_var(variable_name, &value); + env::set_var(env_variable_name, &value); interpolated_snippet = if value.as_str() == "\n" { interpolated_snippet.replacen(bracketed_variable_name, "", 1) diff --git a/src/display/terminal.rs b/src/display/terminal.rs index 7e3514b..fa24b95 100644 --- a/src/display/terminal.rs +++ b/src/display/terminal.rs @@ -84,11 +84,12 @@ pub fn preview_var(selection: &str, query: &str, variable: &str) { let is_current = variable_name == variable; let variable_color = if is_current { active_color } else { inactive_color }; + let env_variable_name = variable_name.replace('-', "_"); let value = if is_current { let v = selection.trim_matches('\''); if v.is_empty() { query.trim_matches('\'') } else { v }.to_string() - } else if let Ok(v) = env::var(&variable_name) { + } else if let Ok(v) = env::var(&env_variable_name) { v } else { "".to_string() @@ -101,7 +102,7 @@ pub fn preview_var(selection: &str, query: &str, variable: &str) { reset = reset ); - colored_snippet = colored_snippet.replacen(bracketed_variable_name, &replacement, 999); + colored_snippet = colored_snippet.replace(bracketed_variable_name, &replacement); variables = format!( "{variables}\n{color}{variable}{reset} = {value}", |