fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Peter AmmonClean up "strip control characters" changes17fdd2f15

master
3.8 KiB111 linesraw
1function fish_fossil_prompt --description 'Write out the fossil prompt'
2    # Bail if fossil is not available
3    if not command -sq fossil
4        return 1
5    end
6
7    # Read branch and bookmark (bail if not checkout)
8    set -l branch (fossil branch current 2>/dev/null)
9    or return 127
10
11    set -q fish_color_fossil_clean
12    or set -g fish_color_fossil_clean green
13    set -q fish_color_fossil_modified
14    or set -g fish_color_fossil_modified yellow
15    set -q fish_color_fossil_dirty
16    or set -g fish_color_fossil_dirty red
17
18    set -q fish_color_fossil_added
19    or set -g fish_color_fossil_added green
20    set -q fish_color_fossil_renamed
21    or set -g fish_color_fossil_renamed magenta
22    set -q fish_color_fossil_missing
23    or set -g fish_color_fossil_missing red
24    set -q fish_color_fossil_deleted
25    or set -g fish_color_fossil_deleted red
26    set -q fish_color_fossil_untracked
27    or set -g fish_color_fossil_untracked yellow
28    set -q fish_color_fossil_conflict
29    or set -g fish_color_fossil_conflict red
30
31    set -q fish_prompt_fossil_status_added
32    or set -g fish_prompt_fossil_status_added '✚'
33    set -q fish_prompt_fossil_status_modified
34    or set -g fish_prompt_fossil_status_modified '*'
35    set -q fish_prompt_fossil_status_renamed
36    or set -g fish_prompt_fossil_status_renamed '⇒'
37    set -q fish_prompt_fossil_status_deleted
38    or set -g fish_prompt_fossil_status_deleted -
39    set -q fish_prompt_fossil_status_missing
40    or set -g fish_prompt_fossil_status_missing '✖'
41    set -q fish_prompt_fossil_status_untracked
42    or set -g fish_prompt_fossil_status_untracked '?'
43    set -q fish_prompt_fossil_status_conflict
44    or set -g fish_prompt_fossil_status_conflict '×'
45
46    set -q fish_prompt_fossil_status_order
47    or set -g fish_prompt_fossil_status_order added modified renamed deleted missing untracked conflict
48
49    echo -n ' ('
50    set_color magenta
51    echo -n "$branch" | string replace -ra '[[:cntrl:]]' ''
52    set_color --reset
53    echo -n '|'
54    #set -l repo_status (fossil changes --differ 2>/dev/null | string match -rv '\w:|^\s' | string split " " -f1 | sort -u)
55    set -l repo_status (fossil changes --differ 2>/dev/null | string match -rv '\w:|^\s' | string split " " -f1 | path sort -u)
56
57    # Show nice color for a clean repo
58    if test -z "$repo_status"
59        set_color $fish_color_fossil_clean
60        echo -n '✔'
61
62        # Handle modified or dirty (unknown state)
63    else
64        set -l fossil_statuses
65
66        # Take actions for the statuses of the files in the repo
67        for line in $repo_status
68
69            # Add a character for each file status if we have one
70            switch $line
71                case ADDED
72                    set -a fossil_statuses added
73                case EDITED
74                    set -a fossil_statuses modified
75                case EXTRA
76                    set -a fossil_statuses untracked
77                case DELETED
78                    set -a fossil_statuses deleted
79                case MISSING
80                    set -a fossil_statuses missing
81                case RENAMED
82                    set -a fossil_statuses renamed
83                case CONFLICT
84                    set -a fossil_statuses conflict
85            end
86        end
87
88        if string match -qr '^(ADDED|EDITED|DELETED)' $repo_status
89            set_color $fish_color_fossil_modified
90        else
91            set_color --bold $fish_color_fossil_dirty
92        end
93
94        echo -n '⚡'
95        set_color --reset
96
97        # Sort status symbols
98        for i in $fish_prompt_fossil_status_order
99            if contains -- $i $fossil_statuses
100                set -l color_name fish_color_fossil_$i
101                set -l status_name fish_prompt_fossil_status_$i
102
103                set_color $$color_name
104                echo -n $$status_name
105            end
106        end
107    end
108
109    set_color --reset
110    echo -n ')'
111end