Skip to content

Commit 55f767b

Browse files
LittleJianCHdjc
authored andcommitted
feat: add nushell support
1 parent bd5ce47 commit 55f767b

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/cli/self_update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ the corresponding `env` file under {cargo_home}.
384384
This is usually done by running one of the following (note the leading DOT):
385385
. "{cargo_home}/env" # For sh/bash/zsh/ash/dash/pdksh
386386
source "{cargo_home}/env.fish" # For fish
387+
source "{cargo_home}/env.nu" # For nushell
387388
"#
388389
};
389390
}

src/cli/self_update/env.nu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if ("{cargo_bin}" not-in ($env.Path | split row (char esep))) {
2+
$env.Path = ($env.Path | prepend "{cargo_bin}")
3+
}

src/cli/self_update/shell.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ fn enumerate_shells() -> Vec<Shell> {
7777
Box::new(Bash),
7878
Box::new(Zsh),
7979
Box::new(Fish),
80+
Box::new(Nu),
8081
]
8182
}
8283

@@ -255,6 +256,53 @@ impl UnixShell for Fish {
255256
}
256257
}
257258

259+
struct Nu;
260+
261+
impl UnixShell for Nu {
262+
fn does_exist(&self, process: &Process) -> bool {
263+
// nu has to either be the shell or be callable for nu setup.
264+
matches!(process.var("SHELL"), Ok(sh) if sh.contains("nu"))
265+
|| utils::find_cmd(&["nu"], process).is_some()
266+
}
267+
268+
fn rcfiles(&self, process: &Process) -> Vec<PathBuf> {
269+
let mut paths = vec![];
270+
271+
if let Ok(p) = process.var("XDG_CONFIG_HOME") {
272+
let path = PathBuf::from(p).join("nushell/");
273+
paths.push(path.join("env.nu"));
274+
paths.push(path.join("config.nu"));
275+
}
276+
277+
if let Some(p) = process.home_dir() {
278+
let path = p.join(".config/nushell/");
279+
paths.push(path.join("env.nu"));
280+
paths.push(path.join("config.nu"));
281+
}
282+
paths
283+
}
284+
285+
fn update_rcs(&self, process: &Process) -> Vec<PathBuf> {
286+
let mut rcs = self.rcfiles(process);
287+
if rcs.len() == 4 {
288+
// The first two rcfile takes precedence (XDG_CONFIG_HOME).
289+
rcs.truncate(2);
290+
}
291+
rcs
292+
}
293+
294+
fn env_script(&self) -> ShellScript {
295+
ShellScript {
296+
name: "env.nu",
297+
content: include_str!("env.nu"),
298+
}
299+
}
300+
301+
fn source_string(&self, process: &Process) -> Result<String> {
302+
Ok(format!(r#"source "{}/env.nu""#, cargo_home_str(process)?))
303+
}
304+
}
305+
258306
pub(crate) fn legacy_paths(process: &Process) -> impl Iterator<Item = PathBuf> + '_ {
259307
let zprofiles = Zsh::zdotdir(process)
260308
.into_iter()

0 commit comments

Comments
 (0)