Skip to content

Commit

Permalink
fix nushell integration
Browse files Browse the repository at this point in the history
/ref 61662e8

setup-util-nu: fix self-load infinite loop with defaults
1a735c7

setup-util-nu/starship.nu: fixed and improved starship theme setup
ab2d6ad

dorothy-workflow.yml: implement workaround for -l not loading login.nu
b653506
  • Loading branch information
balupton committed Sep 2, 2023
1 parent a9b2a29 commit c53ab02
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/dorothy-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
setup-util-fish
setup-util-nu
dorothy install
echo-file "$(nu -c 'echo $nu.loginshell-path')"
- name: 'Dorothy Login Shell: bash'
shell: bash -leo pipefail {0}
run: |
Expand All @@ -52,6 +51,9 @@ jobs:
- name: 'Dorothy Login Shell: nu'
shell: nu -l {0}
run: |
# source ... is a workaround for: https://discord.com/channels/601130461678272522/1147584426121896067
source '/Users/runner/Library/Application Support/nushell/login.nu'
# continue as normal
command-exists dorothy
echo-style --success='ok'
- name: 'Trunk Format'
Expand Down
29 changes: 7 additions & 22 deletions commands/setup-util-nu
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,25 @@ 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
cat <<-EOF >"$DOROTHY/user/config.local/interactive.nu"
#!/usr/bin/env nu
# load the dorothy defaults
source ~/.local/share/dorothy/config/interactive.nu
# load my public configuration
source ../config/interactive.nu
EOF
fi
if test ! -f "$DOROTHY/user/config/interactive.nu"; then
cat <<-EOF >"$DOROTHY/user/config/interactive.nu"
#!/usr/bin/env nu
# load my public configuration
source ../config/interactive.nu
# load the dorothy defaults
source ~/.local/share/dorothy/config/interactive.nu
EOF
fi
}
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 c53ab02

Please sign in to comment.