+62
-11
mira.nu
+62
-11
mira.nu
···
7
7
return $user_color
8
8
}
9
9
10
+
def get-jj-line [] {
11
+
try {
12
+
let jj_bookmark = (jj log -r @ --no-graph -T 'bookmarks' err> /dev/null | str trim)
13
+
let jj_id = (jj log -r @ --no-graph -T 'change_id.short()' err> /dev/null | str trim)
14
+
15
+
if $jj_bookmark != "" { $"($jj_id) \(($jj_bookmark)\)" } else { $jj_id }
16
+
} catch {
17
+
""
18
+
}
19
+
}
20
+
21
+
def get-git-line [] {
22
+
try {
23
+
let git_branch = (git branch --show-current err> /dev/null | str trim)
24
+
let git_dirty = (git status --porcelain=v1 err> /dev/null | wc -l | into int) > 0
25
+
26
+
$"($git_branch)(if $git_dirty { "*" } else { "" })"
27
+
} catch {
28
+
""
29
+
}
30
+
}
31
+
32
+
def get-hg-line [] {
33
+
try {
34
+
let hg_id = (hg id -i err> /dev/null | str trim | str replace '+' '')
35
+
let hg_dirty = (hg id -i err> /dev/null | str contains '+')
36
+
37
+
$"($hg_id)(if $hg_dirty { "*" } else { "" })"
38
+
} catch {
39
+
""
40
+
}
41
+
}
42
+
43
+
def get-pijul-line [] {
44
+
try {
45
+
let pijul_channel = (pijul channel err> /dev/null | lines | where $it starts-with '*' | first | str trim |
46
+
str replace '* ' '')
47
+
let pijul_dirty = (pijul diff --short err> /dev/null | str length) > 0
48
+
49
+
$"($pijul_channel)(if $pijul_dirty { "*" } else { "" })"
50
+
} catch {
51
+
""
52
+
}
53
+
}
54
+
55
+
def first-non-empty [funcs: list] {
56
+
for func in $funcs {
57
+
let result = (do $func)
58
+
if $result != "" {
59
+
return $result
60
+
}
61
+
}
62
+
return ""
63
+
}
64
+
10
65
export def prompt-command [] {
11
66
let user_color = get-user-color
12
67
···
21
76
let user_directory_color = { fg: blue, attr: b }
22
77
let directory = $"(ansi $user_directory_color)(pwd | str replace $env.HOME "~")(ansi reset)"
23
78
24
-
let git_line = (try {
25
-
let git_branch = (git branch --show-current err> /dev/null | str trim)
26
-
let git_dirty = (git status --porcelain=v1 err> /dev/null | wc -l | into int) > 0
27
-
28
-
$"($git_branch)(if $git_dirty { "*" } else { "" })"
29
-
} catch {
30
-
""
31
-
})
79
+
# Try each VCS in order, short-circuiting on first match
80
+
let vcs_line = (first-non-empty [
81
+
{|| get-jj-line },
82
+
{|| get-git-line },
83
+
{|| get-hg-line },
84
+
{|| get-pijul-line }
85
+
])
32
86
33
87
let vcs_color = { fg: yellow }
34
-
# This is a bit unnecessary, but if I decide to support other VCSs in the future
35
-
# it should be relatively easy to tack on
36
-
let vcs_line = (if $git_line != "" { $git_line } else { "" })
37
88
let vcs_line = (if $vcs_line != "" {
38
89
$"(ansi $vcs_color)‹($vcs_line)› (ansi reset)"
39
90
} else {