fork/fish-shell

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

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

master
3.1 KiB87 linesraw
1# name: Disco
2# author: Fabian Homborg
3
4function fish_prompt
5    set -l last_status $status
6
7    set -l normal (set_color --reset)
8    set -l usercolor (set_color $fish_color_user)
9
10    set -l delim \U25BA
11
12    fish_is_root_user; and set delim "#"
13
14    set -l cwd (set_color $fish_color_cwd)
15    if command -sq cksum
16        # randomized cwd color
17        # We hash the physical PWD and turn that into a color. That means directories (usually) get different colors,
18        # but every directory always gets the same color. It's deterministic.
19        # We use cksum because 1. it's fast, 2. it's in POSIX, so it should be available everywhere.
20        set -l shas (pwd -P | cksum | string split -f1 ' ' | math --base=hex | string sub -s 3 | string pad -c 0 -w 6 | string match -ra ..)
21        set -l col 0x$shas[1..3]
22
23        # If the (simplified idea of) luminance is below 120 (out of 255), add some more.
24        # (this runs at most twice because we add 60)
25        while test (math 0.2126 x $col[1] + 0.7152 x $col[2] + 0.0722 x $col[3]) -lt 120
26            set col[1] (math --base=hex "min(255, $col[1] + 60)")
27            set col[2] (math --base=hex "min(255, $col[2] + 60)")
28            set col[3] (math --base=hex "min(255, $col[3] + 60)")
29        end
30        set -l col (string replace 0x '' $col | string pad -c 0 -w 2 | string join "")
31
32        set cwd (set_color $col)
33    end
34
35    # Prompt status only if it's not 0
36    set -l prompt_status
37    test $last_status -ne 0; and set prompt_status (set_color $fish_color_status)"[$last_status]$normal"
38
39    # Only show host if in SSH or container
40    # Store this in a global variable because it's slow and unchanging
41    if not set -q prompt_host
42        set -g prompt_host ""
43        if set -q SSH_TTY
44            or begin
45                command -sq systemd-detect-virt
46                and systemd-detect-virt -q
47            end
48            set prompt_host $usercolor$USER$normal@(set_color $fish_color_host)$hostname$normal":"
49        end
50    end
51
52    # Shorten pwd if prompt is too long
53    set -l pwd (prompt_pwd)
54
55    echo -n -s $prompt_host $cwd $pwd $normal $prompt_status $delim
56end
57
58function fish_right_prompt
59    set -g __fish_git_prompt_showdirtystate 1
60    set -g __fish_git_prompt_showuntrackedfiles 1
61    set -g __fish_git_prompt_showupstream informative
62    set -g __fish_git_prompt_showcolorhints 1
63    set -g __fish_git_prompt_use_informative_chars 1
64    set -g __fish_git_prompt_char_dirtystate \U1F4a9
65    set -g __fish_git_prompt_char_untrackedfiles "?"
66
67    # The git prompt's default format is ' (%s)'.
68    # We don't want the leading space.
69    set -l vcs (fish_vcs_prompt '(%s)' 2>/dev/null)
70
71    set -l d (set_color brgrey)(date "+%R")(set_color --reset)
72
73    set -l duration "$cmd_duration$CMD_DURATION"
74    if test $duration -gt 100
75        set duration (math $duration / 1000)s
76    else
77        set duration
78    end
79
80    set -q VIRTUAL_ENV_DISABLE_PROMPT
81    or set -g VIRTUAL_ENV_DISABLE_PROMPT true
82    set -q VIRTUAL_ENV
83    and set -l venv (string replace -r '.*/' '' -- "$VIRTUAL_ENV")
84
85    set_color --reset
86    string join " " -- $venv $duration $vcs $d
87end