diff --git a/README.md b/README.md index 0e78fcfa..819c2d3e 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,15 @@ shown below. Can't see yours? Have a look at the [extra platform instructions](h # ~/.tcshrc eval `starship init tcsh` + + #### Xonsh + + Add the following to the end of `~/.xonshrc`: + + ```sh + # ~/.xonshrc + + execx($(starship init xonsh)) ``` #### Nushell diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 92249c3b..679e4bb9 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -50,13 +50,13 @@ module.exports = { head: [ ["link", { rel: "icon", href: "/icon.png" }], ["meta", { property: "og:title", content: "Starship: Cross-Shell Prompt" }], - ["meta", { property: "og:description", content: "Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, and Powershell."}], + ["meta", { property: "og:description", content: "Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, Tcsh, Elvish, Nu, Xonsh, and Powershell."}], ["meta", { property: "og:type", content: "website" }], ["meta", { property: "og:url", content: "https://starship.rs/" }], ["meta", { property: "og:image", content: "https://starship.rs/icon.png" }], ["meta", { name: "twitter:card", content: "summary"}], ["meta", { name: "twitter:title", content: "Starship: Cross-Shell Prompt"}], - ["meta", { name: "twitter:description", content: "Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, and Powershell."}], + ["meta", { name: "twitter:description", content: "Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, Tcsh, Elvish, Nu, Xonsh, and Powershell."}], ["meta", { name: "twitter:image", content: "https://starship.rs/icon.png"}], ["meta", { name: "twitter:alt", content: "Starship: Cross-Shell Prompt"}], ], diff --git a/docs/README.md b/docs/README.md index 9ba9a4ae..4014bfc2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,7 +16,7 @@ footer: ISC Licensed | Copyright © 2019-present Starship Contributors # Used for the description meta tag, for SEO metaTitle: "Starship: Cross-Shell Prompt" -description: Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, and PowerShell. +description: Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, Tcsh, Elvish, Nu, Xonsh, and PowerShell. ---
@@ -106,6 +106,7 @@ description: Starship is the minimal, blazing fast, and extremely customizable p eval $(starship init ion) ``` + #### Elvish ::: warning @@ -130,7 +131,7 @@ description: Starship is the minimal, blazing fast, and extremely customizable p eval `starship init tcsh` ``` - #### Nushell + #### Nushell ::: warning This will change in the future. @@ -147,3 +148,13 @@ description: Starship is the minimal, blazing fast, and extremely customizable p ] prompt = "starship_prompt" ``` + + #### Xonsh + + Add the following to the end of `~/.xonshrc`: + + ```sh + # ~/.xonshrc + + execx($(starship init xonsh)) + ``` diff --git a/docs/config/README.md b/docs/config/README.md index 635eff5f..01c305fe 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -2587,6 +2587,7 @@ To enable it, set `disabled` to `false` in your configuration file. | `ion_indicator` | `ion` | A format string used to represent ion. | | `elvish_indicator` | `esh` | A format string used to represent elvish. | | `tcsh_indicator` | `tsh` | A format string used to represent tcsh. | +| `xonsh_indicator` | `xsh` | A format string used to represent xonsh. | | `unknown_indicator` | | The default value to be displayed when the shell is unknown. | | `format` | `$indicator ` | The format for the module. | | `disabled` | `true` | Disables the `shell` module. | diff --git a/install/install.sh b/install/install.sh index 9ae5722b..06d97d59 100755 --- a/install/install.sh +++ b/install/install.sh @@ -456,4 +456,10 @@ info "Please follow the steps for your shell to complete the installation: Add the following to the end of ${BOLD}~/.tcshrc${NO_COLOR}: eval \`starship init tcsh\` + + ${BOLD}${UNDERLINE}Xonsh${NO_COLOR} + Add the following to the end of ${BOLD}~/.xonshrc${NO_COLOR}: + + execx($(starship init xonsh)) + " diff --git a/snapcraft.yaml b/snapcraft.yaml index dd19ada4..7dcf7343 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -42,6 +42,12 @@ description: | `Invoke-Expression (&starship init powershell)` + ### Xonsh + + Add the following to the end of ~/.xonshrc: + + execx($(starship init xonsh)) + grade: stable confinement: strict diff --git a/src/bug_report.rs b/src/bug_report.rs index 28a9bb72..5a2ed061 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -212,6 +212,7 @@ fn get_config_path(shell: &str) -> Option { "zsh" => Some(".zshrc"), "elvish" => Some(".elvish/rc.elv"), "tcsh" => Some(".tcshrc"), + "xonsh" => Some(".xonshrc"), _ => None, } .map(|path| home_dir.join(path)) diff --git a/src/configs/shell.rs b/src/configs/shell.rs index 2f0fc6d1..818130ae 100644 --- a/src/configs/shell.rs +++ b/src/configs/shell.rs @@ -14,6 +14,7 @@ pub struct ShellConfig<'a> { pub elvish_indicator: &'a str, pub tcsh_indicator: &'a str, pub nu_indicator: &'a str, + pub xonsh_indicator: &'a str, pub unknown_indicator: &'a str, pub disabled: bool, } @@ -30,6 +31,7 @@ impl<'a> Default for ShellConfig<'a> { elvish_indicator: "esh", tcsh_indicator: "tsh", nu_indicator: "nu", + xonsh_indicator: "xsh", unknown_indicator: "", disabled: true, } diff --git a/src/context.rs b/src/context.rs index df88636a..d6d51853 100644 --- a/src/context.rs +++ b/src/context.rs @@ -257,6 +257,7 @@ impl<'a> Context<'a> { "elvish" => Shell::Elvish, "tcsh" => Shell::Tcsh, "nu" => Shell::Nu, + "xonsh" => Shell::Xonsh, _ => Shell::Unknown, } } @@ -494,6 +495,7 @@ pub enum Shell { Elvish, Tcsh, Nu, + Xonsh, Unknown, } diff --git a/src/init/mod.rs b/src/init/mod.rs index 893a063c..2450d7ac 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -168,6 +168,10 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> { starship.sprint_posix()? ), "nu" => print_script(NU_INIT, &StarshipPath::init()?.sprint_posix()?), + "xonsh" => print!( + r#"execx($({} init xonsh --print-full-init))"#, + starship.sprint_posix()? + ), _ => { let quoted_arg = shell_words::quote(shell_basename); println!( @@ -181,6 +185,7 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> { * tcsh\\n\ * zsh\\n\ * nu\\n\ + * xonsh\\n\ \\n\ Please open an issue in the starship repo if you would like to \ see support for %s:\\nhttps://github.com/starship/starship/issues/new\\n\\n\" {0} {0}", @@ -204,6 +209,7 @@ pub fn init_main(shell_name: &str) -> io::Result<()> { "ion" => print_script(ION_INIT, &starship_path.sprint()?), "elvish" => print_script(ELVISH_INIT, &starship_path.sprint_posix()?), "tcsh" => print_script(TCSH_INIT, &starship_path.sprint_posix()?), + "xonsh" => print_script(XONSH_INIT, &starship_path.sprint_posix()?), _ => { println!( "printf \"Shell name detection failed on phase two init.\\n\ @@ -251,6 +257,8 @@ const TCSH_INIT: &str = include_str!("starship.tcsh"); const NU_INIT: &str = include_str!("starship.nu"); +const XONSH_INIT: &str = include_str!("starship.xsh"); + #[cfg(test)] mod tests { use super::*; diff --git a/src/init/starship.xsh b/src/init/starship.xsh new file mode 100644 index 00000000..64439d20 --- /dev/null +++ b/src/init/starship.xsh @@ -0,0 +1,17 @@ +import uuid + + +def starship_prompt(): + last_cmd = __xonsh__.history[-1] if __xonsh__.history else None + status = last_cmd.rtn if last_cmd else 0 + # I believe this is equivalent to xonsh.jobs.get_next_job_number() for our purposes, + # but we can't use that function because of https://gitter.im/xonsh/xonsh?at=60e8832d82dd9050f5e0c96a + jobs = sum(1 for job in __xonsh__.all_jobs.values() if job['obj'] and job['obj'].poll() is None) + duration = round((last_cmd.ts[1] - last_cmd.ts[0]) * 1000) if last_cmd else 0 + # The `| cat` is a workaround for https://github.com/xonsh/xonsh/issues/3786. See https://github.com/starship/starship/pull/2807#discussion_r667316323. + return $(::STARSHIP:: prompt --status=@(status) --jobs=@(jobs) --cmd-duration=@(duration) | cat) + + +$PROMPT = starship_prompt +$STARSHIP_SHELL = "xonsh" +$STARSHIP_SESSION_KEY = uuid.uuid4().hex diff --git a/src/main.rs b/src/main.rs index f1bce8fe..e1dff67d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ fn main() { let shell_arg = Arg::with_name("shell") .value_name("SHELL") .help( - "The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion, elvish, tcsh, nu", + "The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion, elvish, tcsh, nu, xonsh", ) .required(true); diff --git a/src/modules/shell.rs b/src/modules/shell.rs index d8a5f8e0..0b141ec8 100644 --- a/src/modules/shell.rs +++ b/src/modules/shell.rs @@ -25,6 +25,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { Shell::Elvish => Some(config.elvish_indicator), Shell::Tcsh => Some(config.tcsh_indicator), Shell::Nu => Some(config.nu_indicator), + Shell::Xonsh => Some(config.xonsh_indicator), Shell::Unknown => Some(config.unknown_indicator), }, _ => None, @@ -37,6 +38,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { "ion_indicator" => Some(Ok(config.ion_indicator)), "elvish_indicator" => Some(Ok(config.elvish_indicator)), "tcsh_indicator" => Some(Ok(config.tcsh_indicator)), + "xonsh_indicator" => Some(Ok(config.xonsh_indicator)), "unknown_indicator" => Some(Ok(config.unknown_indicator)), _ => None, }) @@ -279,6 +281,35 @@ mod tests { assert_eq!(expected, actual); } + #[test] + fn test_xonsh_default_format() { + let expected = Some(format!("{} ", "xsh")); + let actual = ModuleRenderer::new("shell") + .shell(Shell::Xonsh) + .config(toml::toml! { + [shell] + disabled = false + }) + .collect(); + + assert_eq!(expected, actual); + } + + #[test] + fn test_xonsh_custom_format() { + let expected = Some(format!("{} ", Color::Cyan.bold().paint("xonsh"))); + let actual = ModuleRenderer::new("shell") + .shell(Shell::Xonsh) + .config(toml::toml! { + [shell] + xonsh_indicator = "[xonsh](bold cyan)" + disabled = false + }) + .collect(); + + assert_eq!(expected, actual); + } + #[test] fn test_custom_format_conditional_indicator_match() { let expected = Some(format!("{} ", "B"));