diff --git a/commands/setup-util-nu b/commands/setup-util-nu index 23389c0ae..b06bb851e 100755 --- a/commands/setup-util-nu +++ b/commands/setup-util-nu @@ -27,24 +27,9 @@ function setup_util_nu() ( # trunk-ignore(shellcheck/SC2016) mkdir -p "$(nu -c 'echo $nu.default-config-dir')" - # ensure [themes/starship.nu] works - if test ! -f "$XDG_STATE_HOME/starship/init.nu"; then - mkdir -p "$XDG_STATE_HOME/starship" - if command-exists starship; then - starship init nu >"$XDG_STATE_HOME/starship/init.nu" - else - # when the user wants starship theme, install it then and prompt for reload - cat <<-EOF >"$XDG_STATE_HOME/starship/init.nu" - #!/usr/bin/env nu - - echo-style --notice='Starship not yet installed, installing...' - setup-util-starship - echo-style --notice='Configuring Nu for Starship...' - setup-util-nu - echo-style --notice='Reload your terminal...' - EOF - fi - fi + # ensure [themes/starship.nu] works for [themes/starship.nu] to set it up later + mkdir -p "$XDG_STATE_HOME/starship" + touch "$XDG_STATE_HOME/starship/init.nu" # ensure [sources/interactive.nu] works if test ! -f "$DOROTHY/user/config.local/interactive.nu"; then diff --git a/themes/starship.nu b/themes/starship.nu index b7eebe342..025500a58 100644 --- a/themes/starship.nu +++ b/themes/starship.nu @@ -1,16 +1,23 @@ #!/usr/bin/env nu # ensure starship +mut reload_required_for_starship = false command-exists 'starship' | complete -if $env.LAST_EXIT_CODE == 0 { +if $env.LAST_EXIT_CODE != 0 { + # starship is missing, install it setup-util-starship --quiet + $reload_required_for_starship = true +} +if ( open ~/.local/state/starship/init.nu | length ) == 0 { + # init script is placeholder, update it + starship init nu | save --force ~/.local/state/starship/init.nu + $reload_required_for_starship = true +} +if $reload_required_for_starship == true { + # reload the shell to ensure starship is loaded + echo-style --notice='Starship installed, reload your terminal.' + exit 35 # EAGAIN 35 Resource temporarily unavailable } -# ensure starship nushell <-- no point, as nushell requires everything to already be as intended at compile-time -# if ( ~/.local/state/starship/init.nu | path exists ) == false { -# mkdir ~/.local/state/starship -# starship init nu | save ~/.local/state/starship/init.nu -# fi - -# load starship nushell +# load the actual starship init script use ~/.local/state/starship/init.nu