diff --git a/README.md b/README.md index 868beaffe..b04db86f4 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,17 @@ shown below. Can't see yours? Have a look at the [extra platform instructions](h eval $(starship init ion) ``` + #### Elvish + + **Warning** Only elvish v0.15 or higher is supported. + Add the following to the end of `~/.elvish/rc.elv`: + + ```sh + # ~/.elvish/rc.elv + + eval (starship init elvish) + ``` + ## 🤝 Contributing We are always looking for contributors of **all skill levels**! If you're looking to ease your way into the project, try out a [good first issue](https://github.com/starship/starship/labels/🌱%20good%20first%20issue). diff --git a/docs/README.md b/docs/README.md index c3022b298..5fdedb9cf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -101,3 +101,17 @@ description: Starship is the minimal, blazing fast, and extremely customizable p eval $(starship init ion) ``` + #### Elvish + + ::: warning + Only elvish v0.15 or higher is supported. + ::: + + Add the following to the end of `~/.elvish/rc.elv`: + + ```sh + # ~/.elvish/rc.elv + + eval (starship init elvish) + ``` + diff --git a/docs/config/README.md b/docs/config/README.md index 7a1b8a68d..790f23488 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -388,6 +388,10 @@ can do this in two ways: By default it only changes color. If you also want to change it's shape take a look at [this example](#with-custom-error-shape). + +::: warning +`error_symbol` is not supported on elvish shell. +::: ### Options @@ -2263,6 +2267,10 @@ To enable it, set `disabled` to `false` in your configuration file. ::: +::: warning +This module is not supported on elvish shell. +::: + ### Options | Option | Default | Description | diff --git a/src/bug_report.rs b/src/bug_report.rs index 983e4319c..261c7be59 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -203,6 +203,7 @@ fn get_config_path(shell: &str) -> Option { } } "zsh" => Some(".zshrc"), + "elvish" => Some(".elvish/rc.elv"), _ => None, } .map(|path| home_dir.join(path)) diff --git a/src/context.rs b/src/context.rs index 7b0986bf6..293f1bdf6 100644 --- a/src/context.rs +++ b/src/context.rs @@ -208,6 +208,7 @@ impl<'a> Context<'a> { "ion" => Shell::Ion, "powershell" => Shell::PowerShell, "zsh" => Shell::Zsh, + "elvish" => Shell::Elvish, _ => Shell::Unknown, } } @@ -426,6 +427,7 @@ pub enum Shell { Ion, PowerShell, Zsh, + Elvish, Unknown, } diff --git a/src/init/mod.rs b/src/init/mod.rs index f80e8aedc..e8ff73ce2 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -166,6 +166,13 @@ fi"#, let script = format!("eval $({} init ion --print-full-init)", starship.sprint()?); Some(script) } + Some("elvish") => { + let script = format!( + "eval ({} init elvish --print-full-init | slurp)", + starship.sprint_posix()? + ); + Some(script) + } None => { println!( "Invalid shell name provided: {}\\n\ @@ -204,6 +211,7 @@ pub fn init_main(shell_name: &str) -> io::Result<()> { "fish" => print_script(FISH_INIT, &starship_path.sprint_posix()?), "powershell" => print_script(PWSH_INIT, &starship_path.sprint()?), "ion" => print_script(ION_INIT, &starship_path.sprint()?), + "elvish" => print_script(ELVISH_INIT, &starship_path.sprint_posix()?), _ => { println!( "printf \"Shell name detection failed on phase two init.\\n\ @@ -245,3 +253,5 @@ const FISH_INIT: &str = include_str!("starship.fish"); const PWSH_INIT: &str = include_str!("starship.ps1"); const ION_INIT: &str = include_str!("starship.ion"); + +const ELVISH_INIT: &str = include_str!("starship.elv"); diff --git a/src/init/starship.elv b/src/init/starship.elv new file mode 100644 index 000000000..1b84632a8 --- /dev/null +++ b/src/init/starship.elv @@ -0,0 +1,33 @@ +set-env STARSHIP_SHELL "elvish" +set-env STARSHIP_SESSION_KEY (::STARSHIP:: session) + +# Define Hooks +local:cmd-start-time = 0 +local:cmd-end-time = 0 + +fn starship-after-readline-hook [line]{ + cmd-start-time = (::STARSHIP:: time) +} + +fn starship-before-readline-hook { + cmd-end-time = (::STARSHIP:: time) +} + +# Install Hooks +edit:after-readline = [ $@edit:after-readline $starship-after-readline-hook~ ] +edit:before-readline = [ $@edit:before-readline $starship-before-readline-hook~ ] + +# Install starship +edit:prompt = { + # Note: + # Elvish does not appear to support exit status codes (--status) + + if (== $cmd-start-time 0) { + ::STARSHIP:: prompt --jobs=$num-bg-jobs + } else { + ::STARSHIP:: prompt --jobs=$num-bg-jobs --cmd-duration=(- $cmd-end-time $cmd-start-time) + } +} + +# Get rid of default rprompt +edit:rprompt = { } diff --git a/src/main.rs b/src/main.rs index bbaa20fb4..b0b0a6cff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,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", + "The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion, elvish", ) .required(true);