|
1 | | -# Greeting |
2 | | - |
3 | 1 | function fish_greeting |
4 | 2 | fish_logo |
5 | 3 | end |
6 | 4 |
|
7 | | -# Prompt |
8 | | -set hydro_color_pwd green -d |
9 | | -set hydro_color_git brblack |
10 | | -set hydro_color_prompt brblack |
11 | | - |
12 | | -# Tide |
13 | | -set --universal tide_left_prompt_items pwd git |
14 | | -set --universal tide_left_prompt_suffix " \$" |
15 | | -set --universal tide_git_icon "" |
16 | | -set --universal tide_pwd_color_dirs normal |
17 | | -set --universal tide_pwd_color_anchors normal |
| 5 | +# track when commands actually execute |
| 6 | +function __my_prompt_preexec --on-event fish_preexec |
| 7 | + set -g __my_prompt_cmd_executed 1 |
| 8 | +end |
| 9 | + |
| 10 | +function __my_prompt_postexec --on-event fish_postexec |
| 11 | + set -g __my_prompt_last_status $status |
| 12 | +end |
| 13 | + |
| 14 | +function fish_prompt |
| 15 | + # capture previous command status IMMEDIATELY - must be first |
| 16 | + set -l last_status $status |
| 17 | + |
| 18 | + # cache git prompt setup once |
| 19 | + if not set -q __my_prompt_git_inited |
| 20 | + set -g __fish_git_prompt_showdirtystate 1 |
| 21 | + set -g __fish_git_prompt_showuntrackedfiles 0 |
| 22 | + set -g __fish_git_prompt_showcolorhints 0 |
| 23 | + set -g __fish_git_prompt_char_stateseparator '' # stick "*" to branch |
| 24 | + set -g __my_prompt_git_inited 1 |
| 25 | + end |
| 26 | + |
| 27 | + # line 1: cwd + gray annotations |
| 28 | + set_color $fish_color_cwd |
| 29 | + printf '%s' (prompt_pwd) |
| 30 | + set_color normal |
| 31 | + |
| 32 | + # git branch without parentheses |
| 33 | + set -l git_seg (fish_git_prompt "%s") |
| 34 | + |
| 35 | + # duration from CMD_DURATION: ms; switch to seconds >= 1000ms |
| 36 | + set -l dur_ms $CMD_DURATION |
| 37 | + set -l dur_str $dur_ms"ms" |
| 38 | + if test $dur_ms -ge 1000 |
| 39 | + set dur_str (math -s 1 "$dur_ms/1000")"s" |
| 40 | + end |
| 41 | + |
| 42 | + # build annotations: [branch?] <dur> | [status?] |
| 43 | + set -l parts |
| 44 | + if test -n "$git_seg" |
| 45 | + set parts $parts $git_seg |
| 46 | + end |
| 47 | + set parts $parts $dur_str |
| 48 | + |
| 49 | + # only show status if a command was actually executed and failed |
| 50 | + if set -q __my_prompt_cmd_executed; and test $last_status -ne 0 |
| 51 | + set parts $parts " $last_status" |
| 52 | + else |
| 53 | + set parts $parts "" |
| 54 | + end |
| 55 | + |
| 56 | + # clear the command executed flag |
| 57 | + set -e __my_prompt_cmd_executed |
| 58 | + |
| 59 | + if test (count $parts) -gt 0 |
| 60 | + printf ' ' |
| 61 | + set_color brblack |
| 62 | + printf '%s' (string join ' ' -- $parts) |
| 63 | + set_color normal |
| 64 | + end |
| 65 | + printf '\n' |
| 66 | + |
| 67 | + # line 2: prompt char only |
| 68 | + printf '$ ' |
| 69 | +end |
| 70 | + |
0 commit comments