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
This commit is contained in:
Hugo 2023-08-31 19:08:13 +02:00 committed by GitHub
parent 1884409c56
commit 5ca8daacd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 4 deletions

View File

@ -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)"#,