improve git prompt
This commit is contained in:
33
scripts/git.sh
Executable file
33
scripts/git.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
_git () {
|
||||
if git branch --show-current > /dev/null 2>&1
|
||||
then
|
||||
_BRANCH="$(git branch --show-current)"
|
||||
_MODIFIED="$(grep -o "M" <<< "$(git status --short)" | grep -c .)"
|
||||
_UNTRACKED="$(grep -o "??" <<< "$(git status --short)" | grep -c .)"
|
||||
_ORIGIN="$(git remote show)"
|
||||
_AHEAD=$(git rev-list --left-right --count "$_BRANCH"..."$_ORIGIN"/"$_BRANCH" | cut -f 1)
|
||||
_BEHIND=$(git rev-list --left-right --count "$_BRANCH"..."$_ORIGIN"/"$_BRANCH" | cut -f 2)
|
||||
printf " %s " "$(git branch --show-current)"
|
||||
if (( _MODIFIED == 0 )) && (( _UNTRACKED == 0 )) && (( _AHEAD == 0 )) && (( _BEHIND == 0 ))
|
||||
then
|
||||
printf ""
|
||||
exit 0
|
||||
fi
|
||||
if (( _MODIFIED >= 0 ))
|
||||
then
|
||||
printf "✗%s " "$_MODIFIED"
|
||||
fi
|
||||
if (( _UNTRACKED >= 0 ))
|
||||
then
|
||||
printf "★%s " "$_UNTRACKED"
|
||||
fi
|
||||
if (( _AHEAD >= 0 )); then
|
||||
printf "%s " "$_AHEAD"
|
||||
fi
|
||||
if (( _BEHIND >= 0 )); then
|
||||
printf "%s" "$_BEHIND"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user