mirror of
https://github.com/dcarrillo/prezto.git
synced 2024-12-22 21:58:00 +00:00
ZSH has built-in regex support; use it!
This commit is contained in:
parent
19a85909ca
commit
3a444ea70a
55
lib/git.zsh
55
lib/git.zsh
@ -32,31 +32,32 @@ function git_prompt_long_sha() {
|
|||||||
|
|
||||||
# Get the status of the working tree
|
# Get the status of the working tree
|
||||||
git_prompt_status() {
|
git_prompt_status() {
|
||||||
INDEX=$(git status --porcelain 2> /dev/null)
|
local indicators line untracked added modified renamed deleted
|
||||||
STATUS=""
|
while IFS=$'\n' read line; do
|
||||||
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
|
if [[ "$line" =~ '^\?\? ' ]]; then
|
||||||
STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
|
[[ -n $untracked ]] && continue || untracked='yes'
|
||||||
fi
|
indicators="${ZSH_THEME_GIT_PROMPT_UNTRACKED}${indicators}"
|
||||||
if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
|
fi
|
||||||
STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
|
if [[ "$line" =~ '^(((A|M|D|T) )|(AD|AM|AT|MM)) ' ]]; then
|
||||||
elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
|
[[ -n $added ]] && continue || added='yes'
|
||||||
STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
|
indicators="${ZSH_THEME_GIT_PROMPT_ADDED}${indicators}"
|
||||||
fi
|
fi
|
||||||
if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
|
if [[ "$line" =~ '^(( (M|T))|(AM|AT|MM)) ' ]]; then
|
||||||
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
|
[[ -n $modified ]] && continue || modified='yes'
|
||||||
elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then
|
indicators="${ZSH_THEME_GIT_PROMPT_MODIFIED}${indicators}"
|
||||||
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
|
fi
|
||||||
elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then
|
if [[ "$line" =~ '^R ' ]]; then
|
||||||
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
|
[[ -n $renamed ]] && continue || renamed='yes'
|
||||||
fi
|
indicators="${ZSH_THEME_GIT_PROMPT_RENAMED}${indicators}"
|
||||||
if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
|
fi
|
||||||
STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS"
|
if [[ "$line" =~ '^( D|AD) ' ]]; then
|
||||||
fi
|
[[ -n $deleted ]] && continue || deleted='yes'
|
||||||
if $(echo "$INDEX" | grep '^D ' &> /dev/null); then
|
indicators="${ZSH_THEME_GIT_PROMPT_DELETED}${indicators}"
|
||||||
STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
|
fi
|
||||||
fi
|
if [[ "$line" =~ '^UU ' ]]; then
|
||||||
if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
|
[[ -n $unmerged ]] && continue || unmerged='yes'
|
||||||
STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
|
indicators="${ZSH_THEME_GIT_PROMPT_UNMERGED}${indicators}"
|
||||||
fi
|
fi
|
||||||
echo $STATUS
|
done < <(git status --porcelain 2> /dev/null)
|
||||||
|
echo $indicators
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user