summaryrefslogtreecommitdiffstats
path: root/git-base.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xgit-base.sh106
1 files changed, 71 insertions, 35 deletions
diff --git a/git-base.sh b/git-base.sh
index 1c6ba0c..35e3596 100755
--- a/git-base.sh
+++ b/git-base.sh
@@ -200,51 +200,87 @@ remote_ahead_of_master() {
fi
}
+added="A%{$reset_color%}"
+modified="M%{$reset_color%}"
+deleted="D%{$reset_color%}"
+renamed="R%{$reset_color%}"
+us="U%{$reset_color%}"
+them="T%{$reset_color%}"
+both="B%{$reset_color%}"
+
+staged="%{$fg_bold[green]%}"
+unstaged="%{$fg_bold[red]%}"
+conflicted="%{$fg_bold[yellow]%}"
+untracked="%{$fg_bold[white]%}"
+
porcelain_status() {
echo "$(git status --porcelain 2>/dev/null)"
}
-count_from_porcelain() {
- if is_repo; then
- current_status="$(porcelain_status)"
- pattern="$1"
- echo "$(echo "$current_status" | grep -p "$pattern" | wc -l | grep -oEi '[0-9][0-9]*')"
- else
- echo "0"
+staged_status() {
+ local gitStatus=${1:-"$(porcelain_status)"}
+ local staged_string=""
+ local filesModified="$(echo "$gitStatus" | grep -p "M[A|M|C|D|U|R ] " | wc -l | grep -oEi '[1-9][0-9]*')"
+ local filesAdded="$(echo "$gitStatus" | grep -p "A[A|M|C|D|U|R ] " | wc -l | grep -oEi '[1-9][0-9]*')"
+ local filesDeleted="$(echo "$gitStatus" | grep -p "D[A|M|C|D|U|R ] " | wc -l | grep -oEi '[1-9][0-9]*')"
+ local filesRenamed="$(echo "$gitStatus" | grep -p "R[A|M|C|D|U|R ] " | wc -l | grep -oEi '[1-9][0-9]*')"
+
+ if [ -n "$filesAdded" ]; then
+ staged_string="$staged_string$filesAdded$staged$added"
fi
+ if [ -n "$filesDeleted" ]; then
+ staged_string="$staged_string$filesDeleted$staged$deleted"
+ fi
+ if [ -n "$filesModified" ]; then
+ staged_string="$staged_string$filesModified$staged$modified"
+ fi
+ if [ -n "$filesRenamed" ]; then
+ staged_string="$staged_string$filesRenamed$staged$renamed"
+ fi
+ echo "$staged_string"
}
-untracked_files() {
- echo "$(count_from_porcelain "?? ")"
+conflicted_status() {
+ local gitStatus=${1:-"$(porcelain_status)"}
+ local conflicted_string=""
+ local filesConflictedUs="$(echo "$gitStatus" | grep -p "[A|M|C|D|R ]U " | wc -l | grep -oEi '[1-9][0-9]*')"
+ local filesConflictedThem="$(echo "$gitStatus" | grep -p "U[A|M|C|D|R ] " | wc -l | grep -oEi '[1-9][0-9]*')"
+ local filesConflictedBoth="$(echo "$gitStatus" | grep -p "UU " | wc -l | grep -oEi '[1-9][0-9]*')"
+
+ if [ -n "$filesConflictedUs" ]; then
+ conflicted_string="$conflicted_string$filesConflictedUs$conflicted$us"
+ fi
+ if [ -n "$filesConflictedBoth" ]; then
+ conflicted_string="$conflicted_string$filesConflictedBoth$conflicted$both"
+ fi
+ if [ -n "$filesConflictedThem" ]; then
+ conflicted_string="$conflicted_string$filesConflictedThem$conflicted$them"
+ fi
+ echo "$conflicted_string"
}
-staged_added_changes() {
- echo "$(count_from_porcelain "A[A|M|C|D|U|R ] ")"
-}
-staged_modified_changes() {
- echo "$(count_from_porcelain "M[A|M|C|D|U|R ] ")"
-}
-staged_deleted_changes() {
- echo "$(count_from_porcelain "D[A|M|C|D|U|R ] ")"
-}
-staged_renamed_changes() {
- echo "$(count_from_porcelain "R[A|M|C|D|U|R ] ")"
-}
+unstaged_status() {
+ local gitStatus=${1:-"$(porcelain_status)"}
+ local unstaged_string=""
+ local filesModified="$(echo "$gitStatus" | grep -p "[A|M|C|D|U|R ]M " | wc -l | grep -oEi '[1-9][0-9]*')"
+ local filesDeleted="$(echo "$gitStatus" | grep -p "[A|M|C|D|U|R ]D " | wc -l | grep -oEi '[1-9][0-9]*')"
-unstaged_modified_changes() {
- echo "$(count_from_porcelain "[A|M|C|D|U|R ]M ")"
-}
-unstaged_deleted_changes() {
- echo "$(count_from_porcelain "[A|M|C|D|U|R ]D ")"
+ if [ -n "$filesDeleted" ]; then
+ unstaged_string="$unstaged_string$filesDeleted$unstaged$deleted"
+ fi
+ if [ -n "$filesModified" ]; then
+ unstaged_string="$unstaged_string$filesModified$unstaged$modified"
+ fi
+ echo "$unstaged_string"
}
-conflicted_by_us_changes() {
- echo "$(count_from_porcelain "[A|M|C|D|R ]U ")"
-}
-conflicted_by_them_changes() {
- echo "$(count_from_porcelain "U[A|M|C|D|R ] ")"
-}
-conflicted_both_changes() {
- echo "$(count_from_porcelain "UU ")"
+untracked_status() {
+ local gitStatus=${1:-"$(porcelain_status)"}
+ local untracked_string=""
+ local filesUntracked="$(echo "$gitStatus" | grep -p "?? " | wc -l | grep -oEi '[1-9][0-9]*')"
+
+ if [ -n "$filesUntracked" ]; then
+ untracked_string="$untracked_string$filesUntracked$untracked$added"
+ fi
+ echo "$untracked_string"
}
-