mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-02 02:19:06 +01:00
Merge 6bd2afe1b8 into 362927003b
This commit is contained in:
commit
2895790ed6
1 changed files with 42 additions and 1 deletions
43
lib/git.zsh
43
lib/git.zsh
|
|
@ -6,6 +6,47 @@ function git_prompt_info() {
|
|||
|
||||
# Checks if working tree is dirty
|
||||
parse_git_dirty() {
|
||||
if [ "true" = "$IS_LEGACY_GIT" ]; then
|
||||
echo $(parse_legacy_git_dirty)
|
||||
else
|
||||
echo $(parse_recent_git_dirty)
|
||||
fi
|
||||
}
|
||||
|
||||
# echos the string 'true' if this git is old enough not to have --ignore-submodules
|
||||
# echos false otherwise
|
||||
get_is_legacy_git() {
|
||||
checkit() {
|
||||
if [ $1 -gt 1 ]; then
|
||||
echo "false"
|
||||
elif [ $1 -eq 1 -a $2 -gt 7 ]; then
|
||||
echo "false"
|
||||
elif [ $1 -eq 1 -a $2 -eq 7 -a $3 -ge 2 ]; then
|
||||
echo "false"
|
||||
else
|
||||
echo "true"
|
||||
fi
|
||||
}
|
||||
echo $(checkit $(git --version | cut -d " " -f 3 | tr '.' ' '))
|
||||
}
|
||||
|
||||
#this is unlikely to change so make it all statically assigned
|
||||
IS_LEGACY_GIT=$(get_is_legacy_git)
|
||||
|
||||
#clean up the namespace slightly by removing the checker function
|
||||
unset -f get_is_legacy_git
|
||||
|
||||
# Checks if working tree is dirty when --ignore-submodules is not present
|
||||
parse_legacy_git_dirty() {
|
||||
if [[ -n $(git status --porcelain 2> /dev/null) ]]; then
|
||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||
else
|
||||
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks if working tree is dirty when git is recent
|
||||
parse_recent_git_dirty() {
|
||||
if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then
|
||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||
else
|
||||
|
|
@ -61,4 +102,4 @@ git_prompt_status() {
|
|||
STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
|
||||
fi
|
||||
echo $STATUS
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue