don't show git status inside .git dir

This commit is contained in:
lowne 2022-05-17 12:22:35 +02:00
parent c774c260d0
commit 99ea7d3425

View File

@ -1,7 +1,9 @@
# git helper functions # git helper functions
# unused # unused
function __git_is_repo -d "Test if the current directory is a Git repository" function __git_is_repo -d "Test if the current directory is a Git repository"
if not command git rev-parse --git-dir > /dev/null 2>/dev/null # don't consider the .git dir as part of the repo
# so we use --show-toplevel (which fails inside .git) instead of --git-dir
if not command git rev-parse --show-toplevel > /dev/null 2>/dev/null
return 1 return 1
end end
end end
@ -140,58 +142,60 @@ function fish_prompt
segment $base_color " $pwd_info[3] " segment $base_color " $pwd_info[3] "
end end
if set branch_name (__git_branch_name) if __git_is_repo
if set branch_name (__git_branch_name)
if __git_is_stashed if __git_is_stashed
segment "$text_color" blue "♺" # "╍╍" segment "$text_color" blue "♺" # "╍╍"
end end
# set -l untracked_files (__git_untracked_files) # set -l untracked_files (__git_untracked_files)
# if test "0" != "$untracked_files" # if test "0" != "$untracked_files"
# segment "$text_color" blue "$untracked_files?" #﹖" # segment "$text_color" blue "$untracked_files?" #﹖"
if __git_has_untracked if __git_has_untracked
segment "$text_color" blue "?" #﹖" segment "$text_color" blue "?" #﹖"
end end
# set -l dirty_files (__git_dirty_files) # set -l dirty_files (__git_dirty_files)
# if test "0" != "$dirty_files" # if test "0" != "$dirty_files"
# segment "$text_color" red "$dirty_files" # segment "$text_color" red "$dirty_files"
if __git_is_dirty if __git_is_dirty
segment "$text_color" red "⁝" # " ╍" segment "$text_color" red "⁝" # " ╍"
end end
# set -l staged_files (__git_staged_files) # set -l staged_files (__git_staged_files)
# if test "0" != "$staged_files" # if test "0" != "$staged_files"
if __git_is_staged if __git_is_staged
segment "$text_color" yellow "🮸 " #"🮶" segment "$text_color" yellow "🮸 " #"🮶"
end
set -l git_color "$split_color" "$text_color"
set -l git_glyph ""
if __git_is_detached_head
set git_glyph "➤"
if __git_is_tag
set git_glyph "🏷"
end end
end
set -l prompt set -l git_color "$split_color" "$text_color"
# set -l git_ahead (__git_ahead "🠕 " "🠗 " "⤲ ") set -l git_glyph ""
set -l git_ahead (__git_ahead) if __git_is_detached_head
if test -z "$git_ahead" set git_glyph "➤"
else if test "+" = "$git_ahead" if __git_is_tag
set git_ahead "🠕" set git_glyph "🏷"
set git_color $text_color green end
else if test "-" = "$git_ahead" end
set git_ahead "🠗"
set git_color $text_color yellow set -l prompt
else # set -l git_ahead (__git_ahead "🠕 " "🠗 " "⤲ ")
set git_ahead "⤲" set -l git_ahead (__git_ahead)
set git_color $text_color red if test -z "$git_ahead"
else if test "+" = "$git_ahead"
set git_ahead "🠕"
set git_color $text_color green
else if test "-" = "$git_ahead"
set git_ahead "🠗"
set git_color $text_color yellow
else
set git_ahead "⤲"
set git_color $text_color red
end
if test "$branch_name" = master -o "$branch_name" = main
set prompt " $git_glyph $git_ahead"
else
set prompt " $git_glyph $branch_name $git_ahead"
end
segment "$git_color[1]" "$git_color[2]" "$prompt"
end end
if test "$branch_name" = master -o "$branch_name" = main
set prompt " $git_glyph $git_ahead"
else
set prompt " $git_glyph $branch_name $git_ahead"
end
segment "$git_color[1]" "$git_color[2]" "$prompt"
end end
segment $base_color " $dir"(set_color $text_color)"$base " segment $base_color " $dir"(set_color $text_color)"$base "