Skip to content

Commit

Permalink
setup-util-nu/starship.nu: fixed and improved starship theme setup
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Sep 2, 2023
1 parent 8261c0f commit ab2d6ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
21 changes: 3 additions & 18 deletions commands/setup-util-nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions themes/starship.nu
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ab2d6ad

Please sign in to comment.