fish: fix prompt

This commit is contained in:
Leonardo Eugênio 2026-06-20 02:47:56 -03:00
parent 621603d0da
commit 3fa5fe9065

View file

@ -17,10 +17,10 @@ function fish_mode_prompt;end
function _fish_prompt_color -a color
# separate line needed for bold normal
set_color $color
set_color "$color"
set_color --bold
set -e argv[1]
echo -en $argv
echo -en "$argv"
end
alias _fish_prompt_warn "_fish_prompt_color 'yellow'"
@ -34,7 +34,7 @@ alias _fish_prompt_accent "_fish_prompt_color '$__accent_color'"
############################################################
function _fish_prompt_git_status -a git_status_s code symbol color
echo $git_status_s | string match -qr "^$code"
echo "$git_status_s" | string match -qr "^$code"
and _fish_prompt_color "$color" "$symbol"
end
@ -148,7 +148,7 @@ function fish_git_prompt
if test -n "$git_log_unpushed"
and not string match -qr "$git_branch" "$git_log_unpushed"
_fish_prompt_normal '↻'
_fish_prompt_warn $git_log_unpushed[1]
_fish_prompt_warn "$git_log_unpushed[1]"
end
end
@ -182,14 +182,14 @@ function fish_program_time_prompt_print -a diff
set -l unit secs
if test $diff -gt 60
if test "$diff" -gt 60
set unit "mins"
set diff (math $diff / 60)
set diff (math "$diff" / 60)
end
if test $diff -gt 60
if test "$diff" -gt 60
set unit "hours"
set diff (math $diff / 60)
set diff (math "$diff" / 60)
end
if test "$diff" -gt 1
@ -198,7 +198,7 @@ function fish_program_time_prompt_print -a diff
# force formatting as 0.1 instead of 0,1
env LC_ALL=C printf "%.02f" "$diff"
)
_fish_prompt_normal $unit
_fish_prompt_normal "$unit"
end
end
@ -208,9 +208,9 @@ function fish_program_time_prompt
return
end
set -l difference (math $__fish_prompt_last_command_end - $__fish_prompt_last_command_start)
set -l difference (math "$__fish_prompt_last_command_end" - "$__fish_prompt_last_command_start")
fish_program_time_prompt_print $difference
fish_program_time_prompt_print "$difference"
set -eg __fish_prompt_last_command_start
set -eg __fish_prompt_last_command_end
@ -223,13 +223,13 @@ end
function fish_vimode_prompt # Not fish_mode_prompt!
if not test $fish_key_bindings = fish_vi_key_bindings
if not test "$fish_key_bindings" = fish_vi_key_bindings
printf '\e[5 q' # Bar
return
end
# Set cursor shape
if test $fish_bind_mode = insert
if test "$fish_bind_mode" = insert
printf '\e[5 q' # Bar
else
printf '\e[1 q' # Block
@ -238,13 +238,13 @@ function fish_vimode_prompt # Not fish_mode_prompt!
# Print mode symbol, N for normal, I for insert, etc...
# on most cases first letter of mode name
_fish_prompt_accent (
switch $fish_bind_mode
switch "$fish_bind_mode"
case replace_one
printf 'o'
case default
printf 'n'
case '*'
printf (string match -r '^.' $fish_bind_mode )
printf (string match -r '^.' "$fish_bind_mode" )
end | string upper
)' '
end
@ -256,9 +256,9 @@ end
function fish_prompt
# Save current status as it may be overwritten before usage
set _status $status
set _status "$status"
_fish_prompt_accent $USER
_fish_prompt_accent "$USER"
_fish_prompt_normal " in "
_fish_prompt_accent (prompt_pwd)
@ -281,11 +281,11 @@ function fish_prompt
fish_vimode_prompt
if test $_status -ne 0
if test "$_status" -ne 0
_fish_prompt_warn "$_status "
end
if test $USER = root
if test "$USER" = root
_fish_prompt_normal '# '
else
_fish_prompt_normal '$ '