|
|
|
@@ -146,8 +146,17 @@ def _pj_palette [] {
|
|
|
|
|
($env.PJ_PROMPT_PALETTE? | default (_pj_palette_default))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def _pj_detect_user [] {
|
|
|
|
|
let name = (try { whoami } catch { "" } | into string | str trim)
|
|
|
|
|
if ($name != "") {
|
|
|
|
|
return $name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
($env.USER? | default ($env.USERNAME? | default "user"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def _pj_runtime_default [] {
|
|
|
|
|
let user = ($env.USER? | default ($env.USERNAME? | default "user"))
|
|
|
|
|
let user = (_pj_detect_user)
|
|
|
|
|
let host = (sys host | get hostname? | default "")
|
|
|
|
|
{
|
|
|
|
|
user: $user
|
|
|
|
@@ -215,12 +224,89 @@ def _pj_format_duration [ms: int] {
|
|
|
|
|
$"($h)h ($m)m ($s)s ($ms_part)ms"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def _pj_truncate_pwd [pwd: string, length: int = 4] {
|
|
|
|
|
let home = ($env.HOME? | default "")
|
|
|
|
|
let normalized_pwd = (($pwd | into string) | str replace -a "\\" "/")
|
|
|
|
|
let normalized_home = (($home | into string) | str replace -a "\\" "/")
|
|
|
|
|
def _pj_is_path_within [path: string, base: string] {
|
|
|
|
|
if ($base == "") {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if ($path == $base) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
($path | str starts-with $"($base)/")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let shown = if ($normalized_home != "" and ($normalized_pwd | str starts-with $normalized_home)) {
|
|
|
|
|
def _pj_git_root_normalized [] {
|
|
|
|
|
if (which ^git | is-empty) {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let top = (^git rev-parse --show-toplevel | complete)
|
|
|
|
|
if ($top.exit_code != 0) {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let raw = (($top.stdout | str trim) | str replace -a "\\" "/")
|
|
|
|
|
if ($raw == "/") {
|
|
|
|
|
"/"
|
|
|
|
|
} else {
|
|
|
|
|
($raw | str trim -r -c "/")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def _pj_truncate_pwd [pwd: string, length: int = 4] {
|
|
|
|
|
let home = (($nu.home-dir? | default ($nu.home-path? | default ($env.HOME? | default ""))) | into string)
|
|
|
|
|
let normalized_pwd_raw = (($pwd | into string) | str replace -a "\\" "/")
|
|
|
|
|
let normalized_home_raw = (($home | into string) | str replace -a "\\" "/")
|
|
|
|
|
|
|
|
|
|
let normalized_pwd = if ($normalized_pwd_raw == "/") {
|
|
|
|
|
"/"
|
|
|
|
|
} else {
|
|
|
|
|
($normalized_pwd_raw | str trim -r -c "/")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let normalized_home = if ($normalized_home_raw == "/") {
|
|
|
|
|
"/"
|
|
|
|
|
} else {
|
|
|
|
|
($normalized_home_raw | str trim -r -c "/")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let in_home = if ($normalized_home == "") {
|
|
|
|
|
false
|
|
|
|
|
} else {
|
|
|
|
|
(_pj_is_path_within $normalized_pwd $normalized_home)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let repo_root = (_pj_git_root_normalized)
|
|
|
|
|
let in_repo = (_pj_is_path_within $normalized_pwd $repo_root)
|
|
|
|
|
|
|
|
|
|
if $in_repo {
|
|
|
|
|
let repo_name = ($repo_root | path basename)
|
|
|
|
|
let rel = if ($normalized_pwd == $repo_root) {
|
|
|
|
|
""
|
|
|
|
|
} else {
|
|
|
|
|
($normalized_pwd | str substring (($repo_root | str length) + 1)..)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let rel_parts = if ($rel == "") {
|
|
|
|
|
[]
|
|
|
|
|
} else {
|
|
|
|
|
($rel | split row "/" | where {|it| $it != "" })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let keep_rel_count = if ($length <= 1) { 0 } else { $length - 1 }
|
|
|
|
|
let shown_rel_parts = if (($rel_parts | length) <= $keep_rel_count) {
|
|
|
|
|
$rel_parts
|
|
|
|
|
} else {
|
|
|
|
|
($rel_parts | last $keep_rel_count)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (($shown_rel_parts | length) == 0) {
|
|
|
|
|
return $"…/($repo_name)"
|
|
|
|
|
} else {
|
|
|
|
|
return $"…/($repo_name)/($shown_rel_parts | str join '/')"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let shown = if $in_home {
|
|
|
|
|
let rest = ($normalized_pwd | str substring ($normalized_home | str length)..)
|
|
|
|
|
if ($rest == "") { "~" } else { $"~($rest)" }
|
|
|
|
|
} else {
|
|
|
|
@@ -235,8 +321,9 @@ def _pj_truncate_pwd [pwd: string, length: int = 4] {
|
|
|
|
|
($shown | str substring 2.. | split row "/" | where {|it| $it != "" })
|
|
|
|
|
} else if ($shown | str starts-with "/") {
|
|
|
|
|
($shown | str substring 1.. | split row "/" | where {|it| $it != "" })
|
|
|
|
|
} else if ($shown =~ '^[A-Za-z]:/') {
|
|
|
|
|
($shown | str substring 3.. | split row "/" | where {|it| $it != "" })
|
|
|
|
|
} else if ($shown =~ '^[A-Za-z]:(/|$)') {
|
|
|
|
|
let start = if ($shown =~ '^[A-Za-z]:/') { 3 } else { 2 }
|
|
|
|
|
($shown | str substring $start.. | split row "/" | where {|it| $it != "" })
|
|
|
|
|
} else {
|
|
|
|
|
($shown | split row "/" | where {|it| $it != "" })
|
|
|
|
|
}
|
|
|
|
@@ -245,7 +332,7 @@ def _pj_truncate_pwd [pwd: string, length: int = 4] {
|
|
|
|
|
"~/"
|
|
|
|
|
} else if ($shown | str starts-with "/") {
|
|
|
|
|
"/"
|
|
|
|
|
} else if ($shown =~ '^[A-Za-z]:/') {
|
|
|
|
|
} else if ($shown =~ '^[A-Za-z]:(/|$)') {
|
|
|
|
|
let drive = ($shown | str substring 0..1)
|
|
|
|
|
$"($drive)/"
|
|
|
|
|
} else {
|
|
|
|
|