aboutsummaryrefslogtreecommitdiff
path: root/cfg/fish/fish_prompt.fish
blob: 355539be0517357ea64a30b8eca6ffdc3a01929c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function fish_prompt
    set -l user $USER
    set -l cwd $PWD
    set -l home $HOME
    set -l pr_prefix ""
    set -l at_sym "∈"
    set -l on_sym "⊢"
    set -l prompt_sym "λ"
    set -l root_dir_sym ""
    set -l branch_sym ""
    set -l branch ""
    
    if test "$user" = "root"
        set prompt_sym "#"
    end

    if test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true"
        #set branch (git branch --show-current 2>/dev/null)
        set branch (git branch --show-current 2>/dev/null); or set branch (git rev-parse --short HEAD 2>/dev/null)
        set branch "$branch_sym"(set_color red)"$branch"
    end

    if test "$cwd" = "$home"
        set colored "~"
        echo -e (set_color white)"$pr_prefix"(set_color red)"$user"(set_color white)" $at_sym "(set_color red)"$colored"(set_color white)"\n"\
                (set_color white)"$prompt_sym "(set_color normal)

    else if string match -q "$home/*" $cwd
        set -l relative (string replace "$home/" (set_color red)"~/" $cwd)
        set -l parts (string split "/" $relative)
        set -l colored ""

        for p in $parts
            if test -n "$p"
                set colored $colored(set_color white)$p(set_color red)"/"
            end
        end

        set colored (string trim -r -c "/" $colored)

		# if in a ~ subdir
        if test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true"
            echo -e (set_color white)"$pr_prefix"(set_color red)"$user"(set_color white)" $at_sym "(set_color red)"$colored"\
                    (set_color white)"$on_sym ""$branch"(set_color white)"\n" \
                    (set_color white)"$prompt_sym "(set_color normal)
        else
            echo -e (set_color white)"$pr_prefix"(set_color red)"$user"(set_color white)" $at_sym "(set_color red)"$colored"(set_color white)"\n"\
                    (set_color white)"$prompt_sym "(set_color normal)
        end
    else
        set -l parts (string split "/" $cwd)
        set -l colored ""

        for p in $parts
            if test -n "$p"
                set colored $colored(set_color white)$p(set_color red)"/"
            end
        end

        set colored (string trim -r -c "/" $colored)
        set colored (set_color red)"$root_dir_sym""$colored"
		# if in any other dir
        if test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true"
            echo -e (set_color white)"$pr_prefix"(set_color red)"$user"(set_color white)" $at_sym "(set_color red)"$colored"\
                    (set_color white)"$on_sym ""$branch"(set_color white)"\n" \
                    (set_color white)"$prompt_sym "(set_color normal)
        else
            echo -e (set_color white)"$pr_prefix"(set_color red)"$user"(set_color white)" $at_sym "(set_color red)"$colored"(set_color white)"\n"\
                    (set_color white)"$prompt_sym "(set_color normal)
        end
    end
end