fork/fish-shell

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

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

master
3.7 KiB143 linesraw
1# name: Nim
2# author: Guilhem "Nim" Saurel − https://github.com/nim65s/dotfiles/
3
4function fish_prompt
5    # This prompt shows:
6    # - green lines if the last return command is OK, red otherwise
7    # - your user name, in red if root or yellow otherwise
8    # - your hostname, in cyan if ssh or blue otherwise
9    # - the current path (with prompt_pwd)
10    # - date +%X
11    # - the current virtual environment, if any
12    # - the current git status, if any, with fish_git_prompt
13    # - the current battery state, if any, and if your power cable is unplugged, and if you have "acpi"
14    # - current background jobs, if any
15
16    # It goes from:
17    # ┬─[nim@Hattori:~]─[11:39:00]
18    # ╰─>$ echo here
19
20    # To:
21    # ┬─[nim@Hattori:~/w/dashboard]─[11:37:14]─[V:django20]─[G:master↑1|●1✚1…1]─[B:85%, 05:41:42 remaining]
22    # │ 2    15054    0%    arrêtée    sleep 100000
23    # │ 1    15048    0%    arrêtée    sleep 100000
24    # ╰─>$ echo there
25
26    set -l retc red
27    test $status = 0; and set retc green
28
29    set -q __fish_git_prompt_showupstream
30    or set -g __fish_git_prompt_showupstream auto
31
32    function _nim_prompt_wrapper
33        set retc $argv[1]
34        set -l field_name $argv[2]
35        set -l field_value $argv[3]
36
37        set_color --reset
38        set_color $retc
39        echo -n '─'
40        set_color -o green
41        echo -n '['
42        set_color --reset
43        test -n $field_name
44        and echo -n $field_name:
45        set_color $retc
46        echo -n $field_value
47        set_color -o green
48        echo -n ']'
49    end
50
51    set_color $retc
52    echo -n '┬─'
53    set_color -o green
54    echo -n [
55
56    if functions -q fish_is_root_user; and fish_is_root_user
57        set_color -o red
58    else
59        set_color -o yellow
60    end
61
62    echo -n $USER
63    set_color -o white
64    echo -n @
65
66    if test -z "$SSH_CLIENT"
67        set_color -o blue
68    else
69        set_color -o cyan
70    end
71
72    echo -n (prompt_hostname)
73    set_color -o white
74    echo -n :(prompt_pwd)
75    set_color -o green
76    echo -n ']'
77
78    # Date
79    _nim_prompt_wrapper $retc '' (date +%X)
80
81    # Vi-mode
82
83    if test "$fish_key_bindings" = fish_vi_key_bindings
84        or test "$fish_key_bindings" = fish_hybrid_key_bindings
85        set -l mode
86        switch $fish_bind_mode
87            case default
88                set mode (set_color --bold red)N
89            case operator f F t T
90                set mode (set_color --bold cyan)N
91            case insert
92                set mode (set_color --bold green)I
93            case replace_one
94                set mode (set_color --bold green)R
95            case replace
96                set mode (set_color --bold cyan)R
97            case visual
98                set mode (set_color --bold magenta)V
99        end
100        set mode $mode(set_color --reset)
101        _nim_prompt_wrapper $retc '' $mode
102    end
103
104    # Virtual Environment
105    set -q VIRTUAL_ENV_DISABLE_PROMPT
106    or set -g VIRTUAL_ENV_DISABLE_PROMPT true
107    set -q VIRTUAL_ENV
108    and _nim_prompt_wrapper $retc V (path basename "$VIRTUAL_ENV")
109
110    # git
111    set -l prompt_git (fish_git_prompt '%s')
112    test -n "$prompt_git"
113    and _nim_prompt_wrapper $retc G $prompt_git
114
115    # Battery status
116    type -q acpi
117    and acpi -a 2>/dev/null | string match -rq off
118    and _nim_prompt_wrapper $retc B (acpi -b | cut -d' ' -f 4-)
119
120    # New line
121    echo
122
123    # Background jobs
124    set_color --reset
125
126    for job in (jobs)
127        set_color $retc
128        echo -n '│ '
129        set_color brown
130        echo $job
131    end
132
133    set_color --reset
134    set_color $retc
135    echo -n '╰─>'
136    set_color -o red
137    echo -n '$ '
138    set_color --reset
139end
140
141# The default mode prompt would be prefixed, which ruins our alignment.
142function fish_mode_prompt
143end