config-dump/nushell/prompt.nu

85 lines
2.6 KiB
Text
Raw Normal View History

2025-07-15 21:31:31 +02:00
use std null_device
2025-07-17 00:55:24 +02:00
export-env {
load-env {
PROMPT_COMMAND: {||
let exit_code = $env.LAST_EXIT_CODE
let jj_root = try { ^jj root err> $null_device } catch { "" }
$env.LAST_EXIT_CODE = 0
let vcs_root = if not ($jj_root | is-empty) { $jj_root } else { "" }
2025-07-15 21:31:31 +02:00
2025-07-17 00:55:24 +02:00
mut path_segment = ""
if not (($vcs_root | is-empty) or ($env.PWD == $vcs_root)) {
# vcs_root is not empty, we're not in the vcs_root of the project
$path_segment = [($vcs_root | path basename) ($env.PWD | path basename)] | str join " @ "
} else {
$path_segment = $env.PWD | path basename
}
2025-07-15 21:31:31 +02:00
2025-07-17 00:55:24 +02:00
let exit_code_segment = if ($exit_code == 0) {
""
} else {
$"(ansi yellow)━┫(ansi red)($exit_code)(ansi yellow)┣━"
}
2025-07-15 21:31:31 +02:00
2025-07-17 00:55:24 +02:00
[$"(ansi yellow)┏" $exit_code_segment "━ " $path_segment "\n"] | str join
}
TRANSIENT_PROMPT_COMMAND: {||
let path_segment = $env.PWD | path basename
2025-07-15 21:31:31 +02:00
2025-07-17 00:55:24 +02:00
let exit_code_segment = if ($env.LAST_EXIT_CODE == 0) {
""
} else {
$"(ansi yellow)━┫(ansi red)($env.LAST_EXIT_CODE)(ansi yellow)┣━"
}
2025-07-15 21:31:31 +02:00
2025-07-17 00:55:24 +02:00
[$"(ansi yellow)━" $exit_code_segment "━ " $path_segment] | str join
}
PROMPT_INDICATOR_VI_INSERT: $"(ansi yellow)┃ "
PROMPT_INDICATOR_VI_NORMAL: $"(ansi yellow)┋ "
# PROMPT_MULTILINE_INDICATOR: "::: "
PROMPT_MULTILINE_INDICATOR: $"(ansi yellow)┃ "
TRANSIENT_PROMPT_INDICATOR_VI_INSERT: " "
TRANSIENT_PROMPT_INDICATOR_VI_NORMAL: " "
TRANSIENT_PROMPT_MULTILINE_INDICATOR: $"(ansi yellow)┃ "
config: (
$env.config? | default {} | merge {
render_right_prompt_on_last_line: true
}
)
PROMPT_COMMAND_RIGHT: {||
let jj_status = try {
jj --quiet --color always --ignore-working-copy log --no-graph --revisions @ --template '
2025-07-15 21:31:31 +02:00
separate(
" ",
if(empty, label("empty", "(empty)")),
coalesce(
surround(
"\"",
"\"",
if(
description.first_line().substr(0, 24).starts_with(description.first_line()),
description.first_line().substr(0, 24),
description.first_line().substr(0, 23) ++ "…"
)
),
label(if(empty, "empty"), description_placeholder)
),
bookmarks.join(", "),
change_id.shortest(),
commit_id.shortest(),
if(conflict, label("conflict", "(conflict)")),
if(divergent, label("divergent prefix", "(divergent)")),
if(hidden, label("hidden prefix", "(hidden)")),
)
' err> $null_device
2025-07-17 00:55:24 +02:00
} catch {
""
}
$jj_status
}
2025-07-15 21:31:31 +02:00
}
2025-07-17 00:55:24 +02:00
}