aboutsummaryrefslogtreecommitdiff
path: root/cfg/fish/fish_prompt.fish
blob: b14256fb3194e68a9cc4d863f90661076f10b320 (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
function fish_prompt
    set -l user $USER
    set -l cwd $PWD
    set -l home $HOME
    
    if test "$cwd" = "$home"
		# if in ~
        echo -e (set_color white)"("(set_color red)"$user"(set_color white)" at "(set_color red)"~"(set_color white)")\n" \
				(set_color white)"λ "(set_color normal)
        # max at ~
        # λ
    else if string match -q "$home/*" $cwd
        set -l relative (string replace "$home/" "~/" $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
        echo -e (set_color white)"("(set_color red)"$user"(set_color white)" at "(set_color red)"$colored"(set_color white)")\n" \
				(set_color white)"λ "(set_color normal)
    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)"#"$colored
		# if in any other dir
        echo -e (set_color white)"("(set_color red)"$user"(set_color white)" at "(set_color red)"$colored"(set_color white)")\n" \
				(set_color white)"λ "(set_color normal)
    end
end