fork/fish-shell

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

Nahorcolor: prefer `set_color --reset` over `set_color normal`867946468

master
2.4 KiB93 linesraw
1# name: Arrow
2# author: Bruno Ferreira Pinto, Pawel Zubrycki
3
4function fish_prompt
5    set -l __last_command_exit_status $status
6
7    if not set -q -g __fish_arrow_functions_defined
8        set -g __fish_arrow_functions_defined
9        function _git_branch_name
10            set -l branch (git symbolic-ref --quiet HEAD 2>/dev/null)
11            if set -q branch[1]
12                echo (string replace -r '^refs/heads/' '' $branch)
13            else
14                echo (git rev-parse --short HEAD 2>/dev/null)
15            end
16        end
17
18        function _is_git_dirty
19            not command git diff-index --cached --quiet HEAD -- &>/dev/null
20            or not command git diff --no-ext-diff --quiet --exit-code &>/dev/null
21        end
22
23        function _is_git_repo
24            type -q git
25            or return 1
26            git rev-parse --git-dir >/dev/null 2>&1
27        end
28
29        function _hg_branch_name
30            echo (hg branch 2>/dev/null)
31        end
32
33        function _is_hg_dirty
34            set -l stat (hg status -mard 2>/dev/null)
35            test -n "$stat"
36        end
37
38        function _is_hg_repo
39            fish_print_hg_root >/dev/null
40        end
41
42        function _repo_branch_name
43            _$argv[1]_branch_name
44        end
45
46        function _is_repo_dirty
47            _is_$argv[1]_dirty
48        end
49
50        function _repo_type
51            if _is_hg_repo
52                echo hg
53                return 0
54            else if _is_git_repo
55                echo git
56                return 0
57            end
58            return 1
59        end
60    end
61
62    set -l cyan (set_color -o cyan)
63    set -l yellow (set_color -o yellow)
64    set -l red (set_color -o red)
65    set -l green (set_color -o green)
66    set -l blue (set_color -o blue)
67    set -l normal (set_color --reset)
68
69    set -l arrow_color "$green"
70    if test $__last_command_exit_status != 0
71        set arrow_color "$red"
72    end
73
74    set -l arrow "$arrow_color➜ "
75    if fish_is_root_user
76        set arrow "$arrow_color# "
77    end
78
79    set -l cwd $cyan(prompt_pwd | path basename)
80
81    set -l repo_info
82    if set -l repo_type (_repo_type)
83        set -l repo_branch $red(_repo_branch_name $repo_type)
84        set repo_info "$blue $repo_type:($repo_branch$blue)"
85
86        if _is_repo_dirty $repo_type
87            set -l dirty "$yellow ✗"
88            set repo_info "$repo_info$dirty"
89        end
90    end
91
92    echo -n -s $arrow ' '$cwd $repo_info $normal ' '
93end