diff --git a/doc/user-guide/src/installation/index.md b/doc/user-guide/src/installation/index.md index d97dd3f7b0..8730088541 100644 --- a/doc/user-guide/src/installation/index.md +++ b/doc/user-guide/src/installation/index.md @@ -100,3 +100,5 @@ For `zsh`, you must then add the following line in your `~/.zshrc` before ```zsh fpath+=~/.zfunc ``` + +In Xonsh you can reuse Fish completion by installing [xontrib-fish-completer](https://github.com/xonsh/xontrib-fish-completer). diff --git a/src/cli/help.rs b/src/cli/help.rs index 802d0de174..dd0d05bc16 100644 --- a/src/cli/help.rs +++ b/src/cli/help.rs @@ -261,6 +261,10 @@ pub(crate) fn completions_help() -> String { This installs the completion script. You may have to log out and log back in to your shell session for the changes to take effect. + {SUBHEADER}Xonsh:{SUBHEADER:#} + + In Xonsh you can reuse Fish completion by installing `xontrib-fish-completer`. + {SUBHEADER}Zsh:{SUBHEADER:#} ZSH completions are commonly stored in any directory listed in diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 2e70b187d9..7f09e5050b 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -457,6 +457,7 @@ This is usually done by running one of the following (note the leading DOT): source $"{cargo_home_nushell}/env.nu" # For nushell source "{cargo_home}/env.tcsh" # For tcsh . "{cargo_home}/env.ps1" # For pwsh + source "{cargo_home}/env.xsh" # For xonsh "# }; } diff --git a/src/cli/self_update/env.xsh b/src/cli/self_update/env.xsh new file mode 100644 index 0000000000..469274c80f --- /dev/null +++ b/src/cli/self_update/env.xsh @@ -0,0 +1 @@ +$PATH.append(_cargo_bin) if (_cargo_bin := '{cargo_bin}') not in $PATH else None diff --git a/src/cli/self_update/shell.rs b/src/cli/self_update/shell.rs index ea48595790..4fb51dfbdd 100644 --- a/src/cli/self_update/shell.rs +++ b/src/cli/self_update/shell.rs @@ -69,6 +69,7 @@ fn enumerate_shells() -> Vec { Box::new(Nu), Box::new(Tcsh), Box::new(Pwsh), + Box::new(Xonsh), ] } @@ -445,6 +446,61 @@ impl UnixShell for Pwsh { } } +struct Xonsh; + +impl UnixShell for Xonsh { + fn does_exist(&self, process: &Process) -> bool { + process.var("XONSHRC").is_ok() || utils::find_cmd(&["xonsh"], process).is_some() + } + + fn rcfiles(&self, process: &Process) -> Vec { + let mut paths = vec![]; + + if let Ok(p) = process.var("XDG_CONFIG_HOME") { + let mut p = PathBuf::from(p); + p.extend(["xonsh", "rc.xsh"]); + paths.push(p); + } + + if let Some(mut p) = process.home_dir() { + p.extend([".config", "xonsh", "rc.xsh"]); + paths.push(p); + } + + if let Some(home) = process.home_dir() { + paths.push(home.join(".xonshrc")); + } + + paths + } + + fn update_rcs(&self, process: &Process) -> Vec { + // The first rcfile in XDG_CONFIG_HOME takes precedence. + match self.rcfiles(process).into_iter().next() { + Some(path) => vec![path], + None => vec![], + } + } + + fn env_script(&self) -> ShellScript { + ShellScript { + name: "env.xsh", + content: include_str!("env.xsh"), + } + } + + fn source_string(&self, process: &Process) -> Result { + Ok(format!( + r#"source "{}/env.xsh""#, + self.cargo_home_str(process)? + )) + } + + fn cargo_home_str(&self, process: &Process) -> Result> { + cargo_home_str_with_home("$HOME", process) + } +} + pub(crate) fn legacy_paths(process: &Process) -> impl Iterator + '_ { let zprofiles = Zsh::zdotdir(process) .into_iter() diff --git a/tests/suite/cli_rustup_ui/rustup_completions_cmd_help_flag.stdout.term.svg b/tests/suite/cli_rustup_ui/rustup_completions_cmd_help_flag.stdout.term.svg index 4016f4f778..55a676da47 100644 --- a/tests/suite/cli_rustup_ui/rustup_completions_cmd_help_flag.stdout.term.svg +++ b/tests/suite/cli_rustup_ui/rustup_completions_cmd_help_flag.stdout.term.svg @@ -1,4 +1,4 @@ - +