-
Notifications
You must be signed in to change notification settings - Fork 237
/
basic-git.nu
70 lines (58 loc) · 1.72 KB
/
basic-git.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Max Brown
# a very basic git prompt
# sort of like panache-git, but fewer than 60 lines of code.
# use as below without the comments and in your
# env.nu file
# use path/to/basic-git.nu basic-git-left-prompt
# $env.PROMPT_COMMAND = {||
# let left = create_left_prompt
# basic-git-left-prompt $left
# }
def in_git_repo [] {
(do --ignore-errors { git rev-parse --abbrev-ref HEAD } | is-empty) == false
}
export def basic-git-left-prompt [in_left_prompt] {
# if we're in a repo, let's go!
let currently_in_git_repo = in_git_repo
if $currently_in_git_repo {
# get the branch info first
let branch_info = git branch -l
| lines
| filter {|e| $e | str contains "*" }
| each {|e| $e | str replace "* " "="}
| get 0
let git_status = git status -s
# get the status in short
let git_status = $git_status
| lines
| str replace -r '(.* ).*' '$1'
| sort
| uniq -c
| insert type {
|e| if ($e.value | str contains "M") {
"blue_bold"
} else if ($e.value | str contains "??") {
"yellow_bold"
} else if ($e.value | str contains "D") {
"red_bold"
} else if ($e.value | str contains "A") {
"cyan_bold"
} else ""
}
| each {
|e| $"(ansi $e.type)($e.count)($e.value | str trim)(ansi reset)"
}
| reduce --fold '' {|str all| $"($all),($str)" }
| str substring 1..
let final_git_status = if $git_status == "" {
""
} else {
$" ($git_status)"
}
# construct the prompt
$"($in_left_prompt)(ansi reset) [($branch_info)($final_git_status)]"
} else {
# otherwise just return the normal prompt
$in_left_prompt
}
}