fix(nushell): improve robustness and clarify abstraction boundaries

- pj_completions: merge into $env.config instead of replacing it wholesale
- pj_completions: use parse-time const for cache dir instead of pwd fallback
- pj_fzf / pj_historyhintcomplete: null-safe keybindings access via ? and default
- pj_helix: replace $env.OS (Windows-only) with $nu.os-info.name; extract shared launcher
- pj_prompt: fix off-by-one in git OID substring (0..7 -> 0..<7)
- pj_prompt: use $nu.os-info.name for OS detection instead of sys host hostname
- pj_prompt: cache git availability in static base, skip per-render which call
- pj_prompt: bind LAST_EXIT_CODE once in right-prompt closure
- pj_brew / pj_uv: add --ignore-errors to hide-env calls
- pj_aliases: convert quote/dadjoke to defs with try/catch error handling
- pj_deepseek: guard curl availability before invoking
- pj_zoxide: add ? to $nu.os-info.name access
- pj_starship: fix null-to-nuon producing "null" string; broaden detection
- nu_polyjuice: load pj_starship module
This commit is contained in:
2026-07-31 00:31:04 +08:00
parent 427fa547a6
commit deb4e45c4e
13 changed files with 78 additions and 80 deletions
+13 -10
View File
@@ -1,9 +1,9 @@
def _pj_detect_os_key [] {
let host_name = (((sys host | get name?) | default ($nu.os-info.name? | default "")) | into string | str lowercase)
if ($host_name | str contains "darwin") {
let os_name = ($nu.os-info.name? | default "" | into string | str lowercase)
if ($os_name | str contains "darwin") {
return "Macos"
}
if ($host_name | str contains "windows") {
if ($os_name | str contains "windows") {
return "Windows"
}
@@ -53,7 +53,7 @@ def _pj_detect_os_key [] {
_ => "Linux"
}
} else {
if ($host_name | str contains "linux") {
if ($os_name | str contains "linux") {
"Linux"
} else {
"Unknown"
@@ -211,8 +211,8 @@ def _pj_is_path_within [path: string, base: string] {
# Single `git rev-parse` call: returns whether we are inside a work tree and the
# normalized repo root (empty string when not in a repo).
def _pj_git_repo_info [] {
if (which ^git | is-empty) {
def _pj_git_repo_info [has_git: bool] {
if not $has_git {
return { inside: false, root: "" }
}
@@ -378,7 +378,7 @@ def _pj_git_info [repo: record] {
} else {
($oid_line | str replace "# branch.oid " "" | str trim)
}
($oid | str substring 0..7)
($oid | str substring 0..<7)
} else {
$head_name
}
@@ -587,6 +587,7 @@ def _pj_prompt_static_base [] {
let in_ssh = (($env.SSH_CONNECTION? | default "") != "" or ($env.SSH_TTY? | default "") != "")
# let prompt_newline = if (($nu.os-info.name | str lowercase) == "windows") { "\n\r" } else { "\n\r" }
let prompt_newline = "\n\r"
let has_git = (which ^git | is-not-empty)
{
os_symbol: (_pj_os_symbol)
@@ -595,6 +596,7 @@ def _pj_prompt_static_base [] {
in_ssh: $in_ssh
shell_name: "nu"
prompt_newline: $prompt_newline
has_git: $has_git
}
}
@@ -611,7 +613,7 @@ def _pj_left_prompt [] {
}
let shell_part = $"($p.c_shell) ($static.shell_name) ($p.c_reset)"
let repo = (_pj_git_repo_info)
let repo = (_pj_git_repo_info $static.has_git)
let dir = (_pj_truncate_pwd $env.PWD 4 $repo)
let git = (_pj_git_info $repo)
let git_part = (_pj_git_branch_module $p $git)
@@ -681,8 +683,9 @@ export-env {
}
PROMPT_COMMAND_RIGHT: {||
let p = ($env.PJ_PROMPT_PALETTE? | default (_pj_palette_default))
if (($env.LAST_EXIT_CODE? | default 0) != 0) {
$"($p.c_right_error)Exit code: ($env.LAST_EXIT_CODE)($p.c_reset)"
let exit_code = ($env.LAST_EXIT_CODE? | default 0)
if ($exit_code != 0) {
$"($p.c_right_error)Exit code: ($exit_code)($p.c_reset)"
} else {
""
}