From 9a580adf1b7f3d682d70661f30897c2532412525 Mon Sep 17 00:00:00 2001 From: Cian Hughes Date: Wed, 29 Jan 2025 10:41:26 +0000 Subject: [PATCH] Fixed shell prompt config property --- dot_config/nushell/env.nu | 1 + dot_config/nushell/prompt.nu | 19 ++++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/dot_config/nushell/env.nu b/dot_config/nushell/env.nu index d772486..aec71fb 100644 --- a/dot_config/nushell/env.nu +++ b/dot_config/nushell/env.nu @@ -5,6 +5,7 @@ use ~/.config/nushell/prompt.nu * # Use nushell functions to define your right and left prompt +$env.STARSHIP_SHELL = "nu" $env.PROMPT_COMMAND = {|| create_left_prompt } $env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt } diff --git a/dot_config/nushell/prompt.nu b/dot_config/nushell/prompt.nu index c804632..00b2193 100644 --- a/dot_config/nushell/prompt.nu +++ b/dot_config/nushell/prompt.nu @@ -1,24 +1,21 @@ -def get_env [s: string]: string -> string { +def get_env [s: string]: string -> any { try { $env | get --ignore-errors $s } catch { "" } } -def get_status []: nothing -> string { - match (get_env "LAST_EXIT_CODE") { - "0" => "0", - _ => "1", - } +export def was_successful []: nothing -> bool { + (get_env "LAST_EXIT_CODE") == 0 } export def create_left_prompt []: nothing -> string { - ^starship prompt --cmd-duration (get_env "CMD_DURATION_MS") --status (get_status) --terminal-width (term size).columns + ^starship prompt --cmd-duration (get_env "CMD_DURATION_MS") $'--status=($env.LAST_EXIT_CODE)' --terminal-width (term size).columns } export def create_right_prompt []: nothing -> string { - ^starship prompt --right --cmd-duration (get_env "CMD_DURATION_MS") --status (get_status) --terminal-width (term size).columns + ^starship prompt --right --cmd-duration (get_env "CMD_DURATION_MS") $'--status=($env.LAST_EXIT_CODE)' --terminal-width (term size).columns } export def create_continuation_prompt []: nothing -> string { - ^starship prompt --continuation --cmd-duration (get_env "CMD_DURATION_MS") --status (get_status) --terminal-width (term size).columns + ^starship prompt --continuation --cmd-duration (get_env "CMD_DURATION_MS") $'--status=($env.LAST_EXIT_CODE)' --terminal-width (term size).columns } def parse_ms_to_human_readable [ms: string]: string -> string { @@ -41,12 +38,12 @@ def parse_ms_to_human_readable [ms: string]: string -> string { } export def create_transient_prompt_left []: nothing -> string { - if (get_env "LAST_EXIT_CODE") == "0" { + if (was_successful) { $"(ansi green_bold)󱔳(ansi reset)" } else { $"(ansi red_bold)󱔷(ansi reset)" } } export def create_transient_prompt_indicator []: nothing -> string { - $"(ansi blue_bold) 󰔛 (parse_ms_to_human_readable (get_env "CMD_DURATION_MS")) (if (get_env "LAST_EXIT_CODE") == "0" { ansi green_bold } else { ansi red_bold })(ansi reset) " + $"(ansi blue_bold) 󰔛 (parse_ms_to_human_readable (get_env "CMD_DURATION_MS")) (if (was_successful) { ansi green_bold } else { ansi red_bold })(ansi reset) " }