From c53ab0294514e225a53fc19527966c7e95b97dc8 Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Sun, 3 Sep 2023 03:56:38 +0800 Subject: [PATCH] fix nushell integration /ref 61662e8b5b920038d8c2d88e9e35ea79766099dd setup-util-nu: fix self-load infinite loop with defaults 1a735c7469ac0a306ac2edbc8c45879013cb5718 setup-util-nu/starship.nu: fixed and improved starship theme setup ab2d6adbfd034d93a2db804603b27899f93dcfcd dorothy-workflow.yml: implement workaround for -l not loading login.nu b653506c177d786291822137e55a8964f0ad7092 --- .github/workflows/dorothy-workflow.yml | 4 +++- commands/setup-util-nu | 29 +++++++------------------- themes/starship.nu | 23 +++++++++++++------- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/.github/workflows/dorothy-workflow.yml b/.github/workflows/dorothy-workflow.yml index 516e4ca8b..96913434f 100755 --- a/.github/workflows/dorothy-workflow.yml +++ b/.github/workflows/dorothy-workflow.yml @@ -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: | @@ -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' diff --git a/commands/setup-util-nu b/commands/setup-util-nu index 194e45c70..b06bb851e 100755 --- a/commands/setup-util-nu +++ b/commands/setup-util-nu @@ -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 } 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