diff options
Diffstat (limited to 'home-config/fish/functions/_tide_item_git.fish')
-rw-r--r-- | home-config/fish/functions/_tide_item_git.fish | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/home-config/fish/functions/_tide_item_git.fish b/home-config/fish/functions/_tide_item_git.fish new file mode 100644 index 0000000..3154acc --- /dev/null +++ b/home-config/fish/functions/_tide_item_git.fish | |||
@@ -0,0 +1,72 @@ | |||
1 | function _tide_item_git | ||
2 | if git branch --show-current 2>/dev/null | string shorten -"$tide_git_truncation_strategy"m$tide_git_truncation_length | read -l location | ||
3 | git rev-parse --git-dir --is-inside-git-dir | read -fL gdir in_gdir | ||
4 | set location $_tide_location_color$location | ||
5 | else if test $pipestatus[1] != 0 | ||
6 | return | ||
7 | else if git tag --points-at HEAD | string shorten -"$tide_git_truncation_strategy"m$tide_git_truncation_length | read location | ||
8 | git rev-parse --git-dir --is-inside-git-dir | read -fL gdir in_gdir | ||
9 | set location '#'$_tide_location_color$location | ||
10 | else | ||
11 | git rev-parse --git-dir --is-inside-git-dir --short HEAD | read -fL gdir in_gdir location | ||
12 | set location @$_tide_location_color$location | ||
13 | end | ||
14 | |||
15 | # Operation | ||
16 | if test -d $gdir/rebase-merge | ||
17 | # Turn ANY into ALL, via double negation | ||
18 | if not path is -v $gdir/rebase-merge/{msgnum,end} | ||
19 | read -f step <$gdir/rebase-merge/msgnum | ||
20 | read -f total_steps <$gdir/rebase-merge/end | ||
21 | end | ||
22 | test -f $gdir/rebase-merge/interactive && set -f operation rebase-i || set -f operation rebase-m | ||
23 | else if test -d $gdir/rebase-apply | ||
24 | if not path is -v $gdir/rebase-apply/{next,last} | ||
25 | read -f step <$gdir/rebase-apply/next | ||
26 | read -f total_steps <$gdir/rebase-apply/last | ||
27 | end | ||
28 | if test -f $gdir/rebase-apply/rebasing | ||
29 | set -f operation rebase | ||
30 | else if test -f $gdir/rebase-apply/applying | ||
31 | set -f operation am | ||
32 | else | ||
33 | set -f operation am/rebase | ||
34 | end | ||
35 | else if test -f $gdir/MERGE_HEAD | ||
36 | set -f operation merge | ||
37 | else if test -f $gdir/CHERRY_PICK_HEAD | ||
38 | set -f operation cherry-pick | ||
39 | else if test -f $gdir/REVERT_HEAD | ||
40 | set -f operation revert | ||
41 | else if test -f $gdir/BISECT_LOG | ||
42 | set -f operation bisect | ||
43 | end | ||
44 | |||
45 | # Git status/stash + Upstream behind/ahead | ||
46 | test $in_gdir = true && set -l _set_dir_opt -C $gdir/.. | ||
47 | # Suppress errors in case we are in a bare repo or there is no upstream | ||
48 | set -l stat (git $_set_dir_opt --no-optional-locks status --porcelain 2>/dev/null) | ||
49 | string match -qr '(0|(?<stash>.*))\n(0|(?<conflicted>.*))\n(0|(?<staged>.*)) | ||
50 | (0|(?<dirty>.*))\n(0|(?<untracked>.*))(\n(0|(?<behind>.*))\t(0|(?<ahead>.*)))?' \ | ||
51 | "$(git $_set_dir_opt stash list 2>/dev/null | count | ||
52 | string match -r ^UU $stat | count | ||
53 | string match -r ^[ADMR]. $stat | count | ||
54 | string match -r ^.[ADMR] $stat | count | ||
55 | string match -r '^\?\?' $stat | count | ||
56 | git rev-list --count --left-right @{upstream}...HEAD 2>/dev/null)" | ||
57 | |||
58 | if test -n "$operation$conflicted" | ||
59 | set -g tide_git_bg_color $tide_git_bg_color_urgent | ||
60 | else if test -n "$staged$dirty$untracked" | ||
61 | set -g tide_git_bg_color $tide_git_bg_color_unstable | ||
62 | end | ||
63 | |||
64 | _tide_print_item git $_tide_location_color$tide_git_icon' ' (set_color white; echo -ns $location | ||
65 | set_color $tide_git_color_operation; echo -ns ' '$operation ' '$step/$total_steps | ||
66 | set_color $tide_git_color_upstream; echo -ns ' ⇣'$behind ' ⇡'$ahead | ||
67 | set_color $tide_git_color_stash; echo -ns ' *'$stash | ||
68 | set_color $tide_git_color_conflicted; echo -ns ' ~'$conflicted | ||
69 | set_color $tide_git_color_staged; echo -ns ' +'$staged | ||
70 | set_color $tide_git_color_dirty; echo -ns ' !'$dirty | ||
71 | set_color $tide_git_color_untracked; echo -ns ' ?'$untracked) | ||
72 | end | ||