Skip to content

Commit

Permalink
properly implemented nushell support for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cptpiepmatz committed Mar 4, 2024
1 parent 2a53493 commit 0af8b2b
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,28 @@ impl ShellEnv for Shell {
match self {
Self::Bash | Self::Sh | Self::Zsh => Ok(format!("export {key}=\"{val}\"")),
Self::Cmd | Self::PowerShell => Ok(format!("$env:{key} = \"{val}\"")),
// use toml format to let nushell parse the values
Self::Nushell => Ok(format!("{key} = \"{val}\"")),
// use toml format to let Nushell parse the values
Self::Nushell => Ok(format!("{key} = '''{val}'''")),
_ => Err(Error::UnsupportedShell),
}
}

fn append_to_path(&self, curr: &str, new: &str) -> Result<String, Error> {
match self {
Self::Bash | Self::Sh | Self::Zsh | Self::Nushell => {
Self::Bash | Self::Sh | Self::Zsh => {
#[cfg(not(windows))]
return Ok(format!("{new}:{curr}"));

#[cfg(windows)]
return Ok(format!("{}:{}", env::to_gitbash_path_var(curr), new));
}
Self::Nushell => {
#[cfg(not(windows))]
return Ok(format!("{new}:{curr}"));

#[cfg(windows)]
return Ok(format!("{new};{curr}"));
}
Self::Cmd | Self::PowerShell => Ok(format!("{new};{curr}")),
_ => Err(Error::UnsupportedShell),
}
Expand Down Expand Up @@ -106,10 +113,26 @@ impl ShellEnv for Shell {
match self {
Self::Bash | Self::Sh | Self::Zsh => Ok(r#"eval "$(goup env)""#),
Self::Cmd | Self::PowerShell => Ok("goup env | Out-String | Invoke-Expression"),
#[cfg(not(windows))]
Self::Nushell => Ok("load-env (goup env | from toml | update PATH {do $env.ENV_CONVERSIONS.PATH.from_string $in})"),
#[cfg(windows)]
Self::Nushell => Ok("load-env (goup env | from toml | update Path {do $env.ENV_CONVERSIONS.Path.from_string $in})"),

// Nushell doesn't support eval
// https://www.nushell.sh/book/how_nushell_code_gets_run.html#eval-function
Self::Nushell => {
#[cfg(not(windows))]
return Ok("load-env (\
goup env \
| from toml \
| update PATH {do $env.ENV_CONVERSIONS.PATH.from_string $in}\
)");

#[cfg(windows)]
return Ok("load-env (\
goup env \
| from toml \
| rename -c {PATH: Path} \
| update Path {do $env.ENV_CONVERSIONS.Path.from_string $in}\
)");
}

_ => Err(Error::UnsupportedShell),
}
}
Expand Down

0 comments on commit 0af8b2b

Please sign in to comment.