Skip to content

Commit 2d9fc7a

Browse files
1rami3l
authored andcommitted
Added xonsh support
1 parent 1450c0d commit 2d9fc7a

File tree

6 files changed

+137
-65
lines changed

6 files changed

+137
-65
lines changed

doc/user-guide/src/installation/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@ For `zsh`, you must then add the following line in your `~/.zshrc` before
100100
```zsh
101101
fpath+=~/.zfunc
102102
```
103+
104+
In Xonsh you can reuse Fish completion by installing [xontrib-fish-completer](https://github.com/xonsh/xontrib-fish-completer).

src/cli/help.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ pub(crate) fn completions_help() -> String {
261261
This installs the completion script. You may have to log out and
262262
log back in to your shell session for the changes to take effect.
263263
264+
{SUBHEADER}Xonsh:{SUBHEADER:#}
265+
266+
In Xonsh you can reuse Fish completion by installing `xontrib-fish-completer`.
267+
264268
{SUBHEADER}Zsh:{SUBHEADER:#}
265269
266270
ZSH completions are commonly stored in any directory listed in

src/cli/self_update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ This is usually done by running one of the following (note the leading DOT):
457457
source $"{cargo_home_nushell}/env.nu" # For nushell
458458
source "{cargo_home}/env.tcsh" # For tcsh
459459
. "{cargo_home}/env.ps1" # For pwsh
460+
source "{cargo_home}/env.xsh" # For xonsh
460461
"#
461462
};
462463
}

src/cli/self_update/env.xsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$PATH.append(_cargo_bin) if (_cargo_bin := '{cargo_bin}') not in $PATH else None

src/cli/self_update/shell.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ fn enumerate_shells() -> Vec<Shell> {
6969
Box::new(Nu),
7070
Box::new(Tcsh),
7171
Box::new(Pwsh),
72+
Box::new(Xonsh),
7273
]
7374
}
7475

@@ -445,6 +446,61 @@ impl UnixShell for Pwsh {
445446
}
446447
}
447448

449+
struct Xonsh;
450+
451+
impl UnixShell for Xonsh {
452+
fn does_exist(&self, process: &Process) -> bool {
453+
process.var("XONSHRC").is_ok() || utils::find_cmd(&["xonsh"], process).is_some()
454+
}
455+
456+
fn rcfiles(&self, process: &Process) -> Vec<PathBuf> {
457+
let mut paths = vec![];
458+
459+
if let Ok(p) = process.var("XDG_CONFIG_HOME") {
460+
let mut p = PathBuf::from(p);
461+
p.extend(["xonsh", "rc.xsh"]);
462+
paths.push(p);
463+
}
464+
465+
if let Some(mut p) = process.home_dir() {
466+
p.extend([".config", "xonsh", "rc.xsh"]);
467+
paths.push(p);
468+
}
469+
470+
if let Some(home) = process.home_dir() {
471+
paths.push(home.join(".xonshrc"));
472+
}
473+
474+
paths
475+
}
476+
477+
fn update_rcs(&self, process: &Process) -> Vec<PathBuf> {
478+
// The first rcfile in XDG_CONFIG_HOME takes precedence.
479+
match self.rcfiles(process).into_iter().next() {
480+
Some(path) => vec![path],
481+
None => vec![],
482+
}
483+
}
484+
485+
fn env_script(&self) -> ShellScript {
486+
ShellScript {
487+
name: "env.xsh",
488+
content: include_str!("env.xsh"),
489+
}
490+
}
491+
492+
fn source_string(&self, process: &Process) -> Result<String> {
493+
Ok(format!(
494+
r#"source "{}/env.xsh""#,
495+
self.cargo_home_str(process)?
496+
))
497+
}
498+
499+
fn cargo_home_str(&self, process: &Process) -> Result<Cow<'static, str>> {
500+
cargo_home_str_with_home("$HOME", process)
501+
}
502+
}
503+
448504
pub(crate) fn legacy_paths(process: &Process) -> impl Iterator<Item = PathBuf> + '_ {
449505
let zprofiles = Zsh::zdotdir(process)
450506
.into_iter()

tests/suite/cli_rustup_ui/rustup_completions_cmd_help_flag.stdout.term.svg

Lines changed: 73 additions & 65 deletions
Loading

0 commit comments

Comments
 (0)