-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstatus.sh
More file actions
executable file
·144 lines (123 loc) · 4.11 KB
/
status.sh
File metadata and controls
executable file
·144 lines (123 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
source "$(dirname $0)/functions.sh"
function realGitStatus() {
title "$1"
smallBlock "41" "$gitBranch"
git status
}
function refreshGitLog() {
commitsToPush=$(git log origin/$gitBranch..$gitBranch 2>/dev/null)
gitLogError=$?
# if local copy of origin is not fresh, $commitsToPush will contains some commits
# who are already pushed, so refresh local copy of origin
if [ "$gitLogError" == "0" ] && [ "$commitsToPush" != "" ]; then
git fetch 1>/dev/null 2>/dev/null
fi
}
function customGitStatus() {
header="$gitBranch"
# get files to commits
allFiles="$(git status --porcelain)"
# commits not pushed
refreshGitLog
commitsToPush=$(git log origin/$gitBranch..$gitBranch 2>/dev/null)
gitLogError=$?
if [ "$gitLogError" == "128" ]; then
header="$header - Branch does not exist on origin"
blockColor=43
blockFontColor=30
elif [ "$gitLogError" != "0" ]; then
header="$header - git log error : $gitLogError"
blockColor=41
blockFontColor=37
elif [ "$commitsToPush" == "" ]; then
header="$header - No push needed"
blockColor=42
blockFontColor=37
else
header="$header - Commits needs to be pushed"
blockColor=43
blockFontColor=30
fi
# nothing to commit / push, don't show this block
if [ "$allFiles" == "" ] && [ "$commitsToPush" == "" ] && [ $showUpToDate == false ]; then
return 0;
fi
# title
if [ $1 == $root ]; then
if [ $showCurrentPathTitle == true ]; then
titleStr="Current path"
else
titleStr=""
fi
elif [ ${1:0:$rootLength} == $root ]; then
titleStr="${1:$rootLength+1}"
else
titleStr="$1"
fi
if [ "$titleStr" != "" ]; then
title "$titleStr"
fi
# header
smallBlock "$blockColor" "$header" "$blockFontColor"
if [ $showLegend = true ]; then
echo -e "[A] Added [M] Modified [D] Deleted [R] Renamed [C] Copied [U] Updated but unmerged [??] Untracked [\033[32mstagged\033[00m] [\033[31mnot stagged\033[00m]"
fi
git status --porcelain|while read; do
fileStatus=${REPLY:0:3}
if [ "$fileStatus" = 'A ' ] || [ "$fileStatus" = 'M ' ] || [ "$fileStatus" = 'D ' ] || [ "$fileStatus" = 'R ' ] || [ "$fileStatus" = 'C ' ] || [ "$fileStatus" = 'U ' ]; then
echo -e "\033[32m$REPLY\033[00m"
elif [ "$fileStatus" = ' A ' ] || [ "$fileStatus" = ' M ' ] || [ "$fileStatus" = ' D ' ] || [ "$fileStatus" = ' R ' ] || [ "$fileStatus" = ' C ' ] || [ "$fileStatus" = ' U ' ] || [ "$fileStatus" = '?? ' ]; then
echo -e "\033[31m$REPLY\033[00m"
else
echo -e "\033[33m$REPLY\033[00m"
fi
done
}
function gitStatus() {
cd $1
gitBranch=$(getGitBranch)
if [ "${gitBranch:0:13}" = "detached from" ] || [ "${gitBranch:0:10}" = "détaché de" ] || [ "${gitBranch:0:13}" = "HEAD détachée" ]; then
if [ $showDetached == true ]; then
realGitStatus "$1"
fi
else
customGitStatus "$1"
fi
}
root=$(pwd)
rootLength=${#root}
paths=$root
showLegend=true
showUpToDate=false
showDetached=true
maxDepth=1000
showCurrentPathTitle=true
for param in $*; do
# -path=[yes/no]
if [ ${param:0:6} = '-path=' ]; then
paramValue="${param:6}"
paths="${paramValue//\%pwd\%/$root}"
# -show-legend=[YES/no]
elif [ $param = '-show-legend=no' ]; then
showLegend=false
# -show-uptodate=[yes/NO]
elif [ $param = '-show-uptodate=yes' ]; then
showUpToDate=true
# -show-detached=[YES/no]
elif [ $param = '-show-detached=no' ]; then
showDetached=false
# -max-depth=[YES/no]
elif [ ${param:0:11} = '-max-depth=' ]; then
maxDepth="${param:11}"
# -show-current-path-title=[yes/NO]
elif [ $param = '-show-current-path-title=no' ]; then
showCurrentPathTitle=false
fi
done
arPath=$(echo $paths | tr "," "\n")
for path in $arPath; do
find -L $path -maxdepth $maxDepth -type d -name .git|while read; do
gitStatus "$(dirname $REPLY)"
done
done