commit 44bcb4832adf7397b035b9859fa512b97f230751 parent 156f93fb413de4afcd7f81e27dc9a4c33460acb2 Author: Toni Brown <me@tb148.net> Date: Tue, 24 Mar 2026 16:10:30 +0800 refactor coloring Diffstat:
| M | config.nu | | | 23 | +++++++++++++---------- |
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/config.nu b/config.nu @@ -47,30 +47,33 @@ let theme = { crust: "#11111b" } +def color [color: string] {$"(ansi $color)($in)(ansi rst)"} + $env.PROMPT_COMMAND = {|| - let last_exit_code = if $env.LAST_EXIT_CODE > 0 {$"(ansi $theme.red)($env.LAST_EXIT_CODE)(ansi rst)"} else {""} - $"(ansi $theme.yellow)(whoami)@(sys host | get hostname)(ansi rst):(ansi $theme.blue)(pwd)(ansi rst)\n($last_exit_code)" + let user_host = $"(whoami)@(sys host | get hostname)" + let last_exit_code = if $env.LAST_EXIT_CODE > 0 {$env.LAST_EXIT_CODE} else {""} + ($user_host | color $theme.yellow) + ("@" | color $theme.text) + (pwd | color $theme.blue) + "\n" + ($last_exit_code | color $theme.red) } $env.PROMPT_COMMAND_RIGHT = {|| let now = date now let duration = $env.CMD_DURATION_MS | into duration -u ms let then = $now - $duration - $"(ansi $theme.overlay1)($then | format date "%H:%M:%S") + ($duration) = ($now | format date "%H:%M:%S")(ansi reset)" + $"($then | format date "%H:%M:%S") + ($duration) = ($now | format date "%H:%M:%S")" | color $theme.overlay1 } $env.PROMPT_INDICATOR = {|| - let indicator_color = if $env.LAST_EXIT_CODE > 0 {ansi $theme.red} else {ansi $theme.green} - $"($indicator_color)(0..<$env.SHLVL | each {">"} | str join)(ansi rst) " + let indicator_color = if $env.LAST_EXIT_CODE > 0 {$theme.red} else {$theme.green} + ((0..<$env.SHLVL | each {">"} | str join) | color $indicator_color) + " " } $env.PROMPT_VI_NORMAL_INDICATOR = {|| - let indicator_color = if $env.LAST_EXIT_CODE > 0 {ansi $theme.red} else {ansi $theme.green} - $"($indicator_color)(0..<$env.SHLVL | each {"<"} | str join)(ansi rst) " + let indicator_color = if $env.LAST_EXIT_CODE > 0 {$theme.red} else {$theme.green} + ((0..<$env.SHLVL | each {"="} | str join) | color $indicator_color) + " " } $env.PROMPT_VI_INSERT_INDICATOR = {|| - let indicator_color = if $env.LAST_EXIT_CODE > 0 {ansi $theme.red} else {ansi $theme.green} - $"($indicator_color)(0..<$env.SHLVL | each {"="} | str join)(ansi rst) " + let indicator_color = if $env.LAST_EXIT_CODE > 0 {$theme.red} else {$theme.green} + ((0..<$env.SHLVL | each {"<"} | str join) | color $indicator_color) + " " } $env.PROMPT_MULTILINE_INDICATOR = {|| - $"(0..<$env.SHLVL | each {char space} | str join) " + 0..$env.SHLVL | each {char space} | str join } $env.TRANSIENT_PROMPT_COMMAND = "" $env.TRANSIENT_PROMPT_COMMAND_RIGHT = ""