Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")
}
48 changes: 48 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,53 @@ 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> {
let mut paths = vec![];

if let Ok(p) = process.var("XDG_CONFIG_HOME") {
let path = PathBuf::from(p).join("nushell/");
paths.push(path.join("env.nu"));
paths.push(path.join("config.nu"));
}

if let Some(p) = process.home_dir() {
let path = p.join(".config/nushell/");
paths.push(path.join("env.nu"));
paths.push(path.join("config.nu"));
}
paths
}

fn update_rcs(&self, process: &Process) -> Vec<PathBuf> {
let mut rcs = self.rcfiles(process);
if rcs.len() == 4 {
// The first two rcfile takes precedence (XDG_CONFIG_HOME).
rcs.truncate(2);
}
rcs
}

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
Loading