diff --git a/src/cli/self_update/env.fish b/src/cli/self_update/env.fish new file mode 100644 index 0000000000..b6549f504d --- /dev/null +++ b/src/cli/self_update/env.fish @@ -0,0 +1,5 @@ +# rustup shell setup +if not contains "{cargo_bin}" $PATH + # Prepending path in case a system-installed rustc needs to be overridden + set -x PATH "{cargo_bin}" $PATH +end diff --git a/src/cli/self_update/shell.rs b/src/cli/self_update/shell.rs index 31c1b84816..3df0fbb526 100644 --- a/src/cli/self_update/shell.rs +++ b/src/cli/self_update/shell.rs @@ -71,7 +71,12 @@ pub(crate) fn cargo_home_str() -> Result> { // TODO?: Make a decision on Ion Shell, Power Shell, Nushell // Cross-platform non-POSIX shells have not been assessed for integration yet fn enumerate_shells() -> Vec { - vec![Box::new(Posix), Box::new(Bash), Box::new(Zsh)] + vec![ + Box::new(Posix), + Box::new(Bash), + Box::new(Zsh), + Box::new(Fish), + ] } pub(crate) fn get_available_shells() -> impl Iterator { @@ -201,6 +206,48 @@ impl UnixShell for Zsh { } } +struct Fish; + +impl UnixShell for Fish { + fn does_exist(&self) -> bool { + // fish has to either be the shell or be callable for fish setup. + matches!(process().var("SHELL"), Ok(sh) if sh.contains("fish")) + || matches!(utils::find_cmd(&["fish"]), Some(_)) + } + + // > "$XDG_CONFIG_HOME/fish/conf.d" (or "~/.config/fish/conf.d" if that variable is unset) for the user + // from + fn rcfiles(&self) -> Vec { + let p0 = process().var("XDG_CONFIG_HOME").ok().map(|p| { + let mut path = PathBuf::from(p); + path.push("fish/conf.d/rustup.fish"); + path + }); + + let p1 = utils::home_dir().map(|mut path| { + path.push(".config/fish/conf.d/rustup.fish"); + path + }); + + p0.into_iter().chain(p1).collect() + } + + fn update_rcs(&self) -> Vec { + self.rcfiles() + } + + fn env_script(&self) -> ShellScript { + ShellScript { + name: "env.fish", + content: include_str!("env.fish"), + } + } + + fn source_string(&self) -> Result { + Ok(format!(r#". "{}/env.fish""#, cargo_home_str()?)) + } +} + pub(crate) fn legacy_paths() -> impl Iterator { let zprofiles = Zsh::zdotdir() .into_iter()