mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 10:06:49 +08:00
fish_git_prompt: Use git status when showDirtystate is enabled
It's faster
This commit is contained in:
parent
f148a0ec35
commit
542a78a4c3
|
@ -258,24 +258,32 @@ function fish_git_prompt --description "Prompt function for Git"
|
|||
set informative_status "$space$informative_status"
|
||||
end
|
||||
else
|
||||
# This has to be set explicitly.
|
||||
if test "$dirty" = true
|
||||
set dirtystate (__fish_git_prompt_dirty)
|
||||
if not test "$dirty" = true; and test "$untracked" = true
|
||||
# Only untracked, ls-files is faster.
|
||||
command git -c core.fsmonitor= ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- :/ >/dev/null 2>&1
|
||||
and set untrackedfiles 1
|
||||
else if test "$dirty" = true
|
||||
# With both dirty and untracked, git status is ~10% faster.
|
||||
# With just dirty, it's ~20%.
|
||||
set -l opt -uno
|
||||
test "$untracked" = true; and set opt -unormal
|
||||
set -l stat (command git -c core.fsmonitor= status --porcelain -z --ignored=no $opt | string split0)
|
||||
|
||||
set dirtystate (string match -qr '^.?M' -- $stat; and echo 1)
|
||||
if test -n "$sha"
|
||||
set stagedstate (__fish_git_prompt_staged)
|
||||
set stagedstate (string match -qr '^[^? ]' -- $stat; and echo 1)
|
||||
else
|
||||
set invalidstate 1
|
||||
end
|
||||
|
||||
test "$untracked" = true
|
||||
and set untrackedfiles (string match -qr '\?\?' -- $stat; and echo 1)
|
||||
end
|
||||
|
||||
if set -q __fish_git_prompt_showstashstate
|
||||
and test -r $git_dir/logs/refs/stash
|
||||
set stashstate 1
|
||||
end
|
||||
|
||||
if test "$untracked" = true
|
||||
set untrackedfiles (__fish_git_prompt_untracked)
|
||||
end
|
||||
end
|
||||
|
||||
if set -q __fish_git_prompt_showupstream
|
||||
|
@ -341,25 +349,6 @@ end
|
|||
|
||||
### helper functions
|
||||
|
||||
function __fish_git_prompt_staged --description "fish_git_prompt helper, tells whether or not the current branch has staged files"
|
||||
# The "diff" functions all return > 0 if there _is_ a diff,
|
||||
# but we want to return 0 if there are staged changes.
|
||||
# So we invert the status.
|
||||
not command git -c core.fsmonitor= diff-index --cached --quiet HEAD -- 2>/dev/null
|
||||
and echo 1
|
||||
end
|
||||
|
||||
function __fish_git_prompt_untracked --description "fish_git_prompt helper, tells whether or not the current repository has untracked files"
|
||||
command git -c core.fsmonitor= ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- :/ >/dev/null 2>&1
|
||||
and echo 1
|
||||
end
|
||||
|
||||
function __fish_git_prompt_dirty --description "fish_git_prompt helper, tells whether or not the current branch has tracked, modified files"
|
||||
# Like staged, invert the status because we want 0 to mean there are dirty files.
|
||||
not command git -c core.fsmonitor= diff --no-ext-diff --quiet --exit-code 2>/dev/null
|
||||
and echo 1
|
||||
end
|
||||
|
||||
function __fish_git_prompt_informative_status
|
||||
set -l stashstate 0
|
||||
set -l stashfile "$argv[1]/logs/refs/stash"
|
||||
|
|
Loading…
Reference in New Issue
Block a user