Skip to content

Commit

Permalink
fix: format env variable for fish shell (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-arts authored Jul 14, 2023
1 parent ac6cd3f commit a98e99d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions crates/rattler_shell/src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ impl Shell for Fish {
writeln!(f, "set -gx {} \"{}\"", env_var, value)
}

fn format_env_var(&self, var_name: &str) -> String {
// Fish doesnt want the extra brackets '{}'
format!("${var_name}")
}

fn unset_env_var(&self, f: &mut impl Write, env_var: &str) -> std::fmt::Result {
writeln!(f, "set -e {}", env_var)
}
Expand Down Expand Up @@ -616,6 +621,18 @@ mod tests {
insta::assert_snapshot!(script.contents);
}

#[test]
fn test_fish() {
let mut script = ShellScript::new(Fish, Platform::Linux64);

script
.set_env_var("FOO", "bar")
.unset_env_var("FOO")
.run_script(&PathBuf::from_str("foo.sh").expect("blah"));

insta::assert_snapshot!(script.contents);
}

#[cfg(feature = "sysinfo")]
#[test]
fn test_from_parent_process_doenst_crash() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: crates/rattler_shell/src/shell/mod.rs
expression: script.contents
---
set -gx FOO "bar"
set -e FOO
source "foo.sh"

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
source: crates/rattler_shell/src/activation.rs
expression: script
---
set -gx PATH "${PATH}:__PREFIX__/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
set -gx PATH "$PATH:__PREFIX__/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
set -gx CONDA_PREFIX "__PREFIX__"

0 comments on commit a98e99d

Please sign in to comment.