Skip to content

Commit

Permalink
feat: add nushell support
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleJianCH committed Nov 15, 2024
1 parent c8eddcb commit 4beed42
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ the corresponding `env` file under {cargo_home}.
This is usually done by running one of the following (note the leading DOT):
. "{cargo_home}/env" # For sh/bash/zsh/ash/dash/pdksh
source "{cargo_home}/env.fish" # For fish
source "{cargo_home}/env.nu" # For nushell
"#
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/cli/self_update/env.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if ("{cargo_bin}" not-in ($env.Path | split row (char esep))) {
$env.Path = ($env.Path | prepend "{cargo_bin}")
}
45 changes: 45 additions & 0 deletions src/cli/self_update/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fn enumerate_shells() -> Vec<Shell> {
Box::new(Bash),
Box::new(Zsh),
Box::new(Fish),
Box::new(Nu),
]
}

Expand Down Expand Up @@ -255,6 +256,50 @@ impl UnixShell for Fish {
}
}

struct Nu;

impl UnixShell for Nu {
fn does_exist(&self, process: &Process) -> bool {
// nu has to either be the shell or be callable for nu setup.
matches!(process.var("SHELL"), Ok(sh) if sh.contains("nu"))
|| utils::find_cmd(&["nu"], process).is_some()
}

fn rcfiles(&self, process: &Process) -> Vec<PathBuf> {
process
.var("XDG_CONFIG_HOME")
.ok()
.and(process.home_dir())
.iter()
.flat_map(|path| {
let mut p0 = path.clone();
let mut p1 = path.clone();
p0.push("nushell/env.nu");
p1.push("nushell/config.nu");
[p0, p1]
})
.collect()
}

fn update_rcs(&self, process: &Process) -> Vec<PathBuf> {
self.rcfiles(process)
.into_iter()
.filter(|rc| rc.is_file())
.collect()
}

fn env_script(&self) -> ShellScript {
ShellScript {
name: "env.nu",
content: include_str!("env.nu"),
}
}

fn source_string(&self, process: &Process) -> Result<String> {
Ok(format!(r#"source "{}/env.nu""#, cargo_home_str(process)?))
}
}

pub(crate) fn legacy_paths(process: &Process) -> impl Iterator<Item = PathBuf> + '_ {
let zprofiles = Zsh::zdotdir(process)
.into_iter()
Expand Down

0 comments on commit 4beed42

Please sign in to comment.