From 5ca8daacd4ce936f97170f814a780b34bfaa486e Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 31 Aug 2023 19:08:13 +0200 Subject: [PATCH] perf: Skip unnecessary indirection in starship init zsh (#5322) Skip unnecessary indirection in starship init zsh The installation instructions indicate that one should add this snippet to zsh's configuration: eval "$(starship init zsh)" The command `starship init zsh` prints a little shell script for zsh to execute: > starship init zsh source <(/usr/bin/starship init zsh --print-full-init)% Running `starship init zsh --print-full-init` prints yet another script that zsh executes. There is an intermediate step that seems redundant; starship prints a script for zsh to execute, and this script prints another script for zsh to execute. This commit skips the intermediate execution and prints the final script in `starship init`. This is backwards compatible and does not require any changes in the installation instructions, so it could be release without a major version bump. Note that it would still be possible to update the installation instructions to `source <(starship init zsh)`; this patch works with both `source` and `eval`. Picking the most performant one is beyond this scope of this commit. See: https://github.com/starship/starship/issues/2637 --- src/init/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/init/mod.rs b/src/init/mod.rs index f0b247c90..90399a187 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -153,10 +153,7 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> { "#, starship.sprint_posix()? ), - "zsh" => print!( - r#"source <({} init zsh --print-full-init)"#, - starship.sprint_posix()? - ), + "zsh" => print_script(ZSH_INIT, &starship.sprint_posix()?), "fish" => print!( // Fish does process substitution with pipes and psub instead of bash syntax r#"source ({} init fish --print-full-init | psub)"#,