|
25 | 25 | test -n "$XDG_CACHE_HOME"; and set prompt_cache_home "$XDG_CACHE_HOME" |
26 | 26 | set -g __prompt_session (random)(random) |
27 | 27 | set -g __prompt_tick 0 |
| 28 | + set -g __prompt_first_render 1 |
28 | 29 | set -g __prompt_git_cache_file "$prompt_cache_home/fish/prompt-git-$fish_pid-$__prompt_session" |
29 | 30 | mkdir -p (dirname $__prompt_git_cache_file) |
30 | 31 |
|
|
64 | 65 | __prompt_bump_tick = { |
65 | 66 | onEvent = "fish_preexec"; |
66 | 67 | body = '' |
67 | | - set -g __prompt_tick (math $__prompt_tick + 1) |
| 68 | + set -e __prompt_git_repaint |
68 | 69 |
|
69 | 70 | if string match --quiet --regex '^\s*(command\s+)?clear(\s|$)' -- "$argv[1]" |
70 | 71 | set -g __prompt_suppress_next_git_repaint 1 |
|
79 | 80 | ''; |
80 | 81 | }; |
81 | 82 |
|
| 83 | + __prompt_clear_git_repaint = { |
| 84 | + onEvent = "fish_postexec"; |
| 85 | + body = '' |
| 86 | + set -e __prompt_git_repaint |
| 87 | + ''; |
| 88 | + }; |
| 89 | + |
82 | 90 | __prompt_reset_git = { |
83 | 91 | onVariable = "PWD"; |
84 | 92 | body = '' |
85 | | - set -g __prompt_tick (math $__prompt_tick + 1) |
86 | 93 | set -e __prompt_git_root |
87 | 94 | set -e __prompt_git_text |
88 | 95 | set -e __prompt_git_loaded_root |
|
107 | 114 | set -l text (string join " " $lines[3..-1]) |
108 | 115 |
|
109 | 116 | if test "$PWD" != "$root"; and not string match --quiet -- "$root/*" "$PWD" |
| 117 | + set -e __prompt_git_pid |
| 118 | + return |
| 119 | + end |
| 120 | +
|
| 121 | + if test "$tick" != "$__prompt_tick" |
| 122 | + set -e __prompt_git_pid |
| 123 | + set -g __prompt_git_repaint 1 |
| 124 | + commandline -f repaint 2>/dev/null |
110 | 125 | return |
111 | 126 | end |
112 | 127 |
|
113 | 128 | set -g __prompt_git_root $root |
114 | 129 | set -g __prompt_git_text $text |
115 | 130 | set -g __prompt_git_loaded_root $root |
116 | | - set -g __prompt_git_loaded_tick $__prompt_tick |
| 131 | + set -g __prompt_git_loaded_tick $tick |
117 | 132 | set -e __prompt_git_pid |
118 | 133 |
|
119 | 134 | if set -q __prompt_suppress_next_git_repaint |
120 | 135 | set -e __prompt_suppress_next_git_repaint |
121 | 136 | return |
122 | 137 | end |
123 | 138 |
|
| 139 | + set -g __prompt_git_repaint 1 |
124 | 140 | commandline -f repaint 2>/dev/null |
125 | 141 | ''; |
126 | 142 | }; |
|
281 | 297 | ''; |
282 | 298 |
|
283 | 299 | fish_prompt = '' |
| 300 | + set -l prompt_status $status $pipestatus |
| 301 | + set -l last_status $prompt_status[1] |
| 302 | + set -l last_pipestatus $prompt_status[2..-1] |
| 303 | + test -n "$last_status"; or set last_status 0 |
| 304 | + test (count $last_pipestatus) -gt 0; or set last_pipestatus $last_status |
| 305 | +
|
| 306 | + if set -q __prompt_git_repaint |
| 307 | + set -e __prompt_git_repaint |
| 308 | + else |
| 309 | + if test "$__prompt_first_render" = 1 |
| 310 | + set -g __prompt_first_render 0 |
| 311 | + set last_status 0 |
| 312 | + set last_pipestatus 0 |
| 313 | + end |
| 314 | + set -g __prompt_tick (math $__prompt_tick + 1) |
| 315 | + end |
| 316 | +
|
284 | 317 | set -l reset (set_color normal) |
285 | 318 | set -l time_color (set_color brblack) |
286 | 319 | set -l user_color (set_color brcyan) |
|
289 | 322 | set -l aws_color (set_color yellow) |
290 | 323 | set -l duration_color (set_color brblack) |
291 | 324 | set -l prompt_color (set_color normal) |
| 325 | + set -l error_color (set_color brred) |
292 | 326 |
|
293 | 327 | set -l parts "$time_color"(command date '+%H:%M')"$reset" |
294 | 328 |
|
|
313 | 347 | set --append parts "$duration_color$duration$reset" |
314 | 348 | end |
315 | 349 |
|
| 350 | + set -l status_text |
| 351 | + if test "$last_status" -ne 0 |
| 352 | + if test (count $last_pipestatus) -gt 1 |
| 353 | + set status_text "["(string join "|" $last_pipestatus)"]" |
| 354 | + else |
| 355 | + set status_text "[$last_status]" |
| 356 | + end |
| 357 | +
|
| 358 | + set --append parts "$error_color$status_text$reset" |
| 359 | + set prompt_color "$error_color" |
| 360 | + end |
| 361 | +
|
316 | 362 | printf '%s\n%s ' (string join ' ' $parts) "$prompt_color❱$reset" |
317 | 363 | ''; |
318 | 364 |
|
|
0 commit comments