fork/fish-shell

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

toastalAdd darcs prompt (#12860)beb32f3ab

master
2.8 KiB93 linesraw
1# Based on the Darc hub ``darcs-fish`` repositories of raichoo & toastal
2
3# For a Darcs-themed prompt try:
4# set fish_color_darcs_normal $__darcs_logo_color
5set -g __darcs_logo_color 72ff01
6# Basic green preferred to clash less with terminal emulator theming
7set -g fish_color_darcs_normal green
8set -g fish_color_darcs_rebasing yellow
9# Conflicts are a critical state that should be resolved
10set -g fish_color_darcs_conflict red
11
12# Darcs doesn’t have branches/channels so just showing the VCS name is more
13# consistent with having text as other VCS prompts do
14set -g fish_prompt_darcs_name darcs
15set -g fish_prompt_darcs_status_added '+'
16set -g fish_prompt_darcs_status_removed -
17set -g fish_prompt_darcs_status_modified '*'
18set -g fish_prompt_darcs_status_moved '→'
19set -g fish_prompt_darcs_status_conflict '!'
20set -g fish_prompt_darcs_status_untracked '…'
21
22set -g fish_prompt_darcs_status_order added removed modified moved conflict untracked
23
24function fish_darcs_prompt --description "Prompt function for Darcs"
25    # No Darcs, no prompt
26    command -sq darcs || return 1
27    # The _darcs metadata directory, must be exist
28    darcs show repo >/dev/null 2>&1 || return 1
29
30    set -l added 0
31    set -l modified 0
32    set -l removed 0
33    set -l moved 0
34    set -l untracked 0
35    set -l conflict 0
36
37    for state_line in (darcs status --machine-readable 2>&1)
38        set -l parts (string split ' ' -- "$state_line")
39        switch $parts[1]
40            case Rebase
41                set rebase $parts[4]
42            case A
43                set added (math "$added + 1")
44            case M
45                set modified (math "$modified + 1")
46            case R
47                set removed (math "$removed + 1")
48            case F
49                set moved (math "$moved + 1")
50            case a
51                set untracked (math "$untracked + 1")
52            case '!'
53                set conflict (math "$conflict + 1")
54        end
55    end
56
57    set_color normal
58    echo -n '('
59    if set -q rebase
60        set_color $fish_color_darcs_rebasing
61    else if test "$conflict" -gt 0
62        set_color $fish_color_darcs_conflict
63    else
64        set_color $fish_color_darcs_normal
65    end
66    echo -n $fish_prompt_darcs_name
67    set_color normal
68    if set -q rebase
69        echo -n "[$rebase]"
70    end
71
72    set -l sep
73    if string length -q -- "$fish_prompt_darcs_name"
74        set sep '|'
75    end
76    for stat in $fish_prompt_darcs_status_order
77        set -l count $$stat
78        if test "$count" -gt 0
79            echo -n "$sep"
80            set -l color_var fish_color_darcs_$stat
81            if set -q $color_var
82                set_color $$color_var
83            end
84            echo -n "$count"
85            set -l symbol_var fish_prompt_darcs_status_$stat
86            echo -n "$$symbol_var"
87            set_color normal
88            set sep /
89        end
90    end
91    set_color normal
92    echo -n ')'
93end