fork/fish-shell

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

Peter AmmonClean up "strip control characters" changes17fdd2f15

master
3.1 KiB107 linesraw
1# Adapted from __terlar_git_prompt
2
3set -g fish_color_hg_clean green
4set -g fish_color_hg_modified yellow
5set -g fish_color_hg_dirty red
6
7set -g fish_color_hg_added green
8set -g fish_color_hg_renamed magenta
9set -g fish_color_hg_copied magenta
10set -g fish_color_hg_deleted red
11set -g fish_color_hg_untracked yellow
12set -g fish_color_hg_unmerged red
13
14set -g fish_prompt_hg_status_added '✚'
15set -g fish_prompt_hg_status_modified '*'
16set -g fish_prompt_hg_status_copied '⇒'
17set -g fish_prompt_hg_status_deleted '✖'
18set -g fish_prompt_hg_status_untracked '?'
19set -g fish_prompt_hg_status_unmerged !
20
21set -g fish_prompt_hg_status_order added modified copied deleted untracked unmerged
22
23function fish_hg_prompt --description 'Write out the hg prompt'
24    # If hg isn't installed, there's nothing we can do
25    # Return 1 so the calling prompt can deal with it
26    if not command -sq hg
27        return 1
28    end
29
30    set -l root (fish_print_hg_root)
31    or return 1
32
33    # Read branch and bookmark
34    set -l branch (cat $root/branch 2>/dev/null; or echo default)
35    if set -l bookmark (cat $root/bookmarks.current 2>/dev/null)
36        set branch "$branch|$bookmark"
37    end
38
39    # Strip control characters for display.
40    set branch (string replace -ra '[[:cntrl:]]' '' -- $branch)
41
42    if not set -q fish_prompt_hg_show_informative_status
43        set_color --reset
44        echo -n " ($branch)"
45        return
46    end
47
48    echo -n '|'
49
50    # Disabling color and pager is always a good idea.
51    set -l repo_status (hg status | string sub -l 2 | sort -u)
52
53    # Show nice color for a clean repo
54    if test -z "$repo_status"
55        set_color $fish_color_hg_clean
56        echo -n "($branch)"'✓'
57        set_color --reset
58
59        # Handle modified or dirty (unknown state)
60    else
61        set -l hg_statuses
62
63        # Take actions for the statuses of the files in the repo
64        for line in $repo_status
65
66            # Add a character for each file status if we have one
67            # HACK: To allow this to work both with and without '?' globs
68            set -l dq '?'
69            switch $line
70                case 'A '
71                    set -a hg_statuses added
72                case 'M ' ' M'
73                    set -a hg_statuses modified
74                case 'C '
75                    set -a hg_statuses copied
76                case 'D ' ' D'
77                    set -a hg_statuses deleted
78                case "$dq "
79                    set -a hg_statuses untracked
80                case 'U*' '*U' DD AA
81                    set -a hg_statuses unmerged
82            end
83        end
84
85        if string match -qr '^[AMCD]' $repo_status
86            set_color $fish_color_hg_modified
87        else
88            set_color $fish_color_hg_dirty
89        end
90
91        echo -n "($branch)"'⚡'
92
93        # Sort status symbols
94        for i in $fish_prompt_hg_status_order
95            if contains -- $i $hg_statuses
96                set -l color_name fish_color_hg_$i
97                set -l status_name fish_prompt_hg_status_$i
98
99                set_color $$color_name
100                echo -n $$status_name
101            end
102        end
103
104        set_color --reset
105    end
106
107end