@@ -18,12 +18,14 @@ cdc() {
18
18
local dir
19
19
local list
20
20
local directory
21
+ local subdir
21
22
local wdir
22
23
local marker
23
24
local cdc_last_element
24
25
local cdc_next_to_last_element
25
26
local cdc_history
26
27
local rc=0
28
+ local dirty=()
27
29
local cdc_list_dirs=false
28
30
local cdc_list_searched_dirs=false
29
31
local cdc_toggle=false
@@ -33,6 +35,7 @@ cdc() {
33
35
local which=false
34
36
local cdc_current=false
35
37
local cdc_pop=false
38
+ local cdc_git_status=false
36
39
local cdc_show_history=false
37
40
local cdc_list_ignored=false
38
41
local print_help=false
@@ -55,7 +58,7 @@ cdc() {
55
58
# If argument contains a slash, it's assumed to contain subdirectories.
56
59
# This splits them into the directory root and its subdirectories.
57
60
if [[ " $1 " == * /* ]]; then
58
- local subdir=" ${1#*/ } "
61
+ subdir=" ${1#*/ } "
59
62
fi
60
63
61
64
# #
@@ -68,7 +71,7 @@ cdc() {
68
71
69
72
# #
70
73
# Case options if present. Suppress errors because we'll supply our own.
71
- while getopts ' acCdDhilLnprRstuUw ' opt 2> /dev/null; do
74
+ while getopts ' acCdDghilLnprRstuUw ' opt 2> /dev/null; do
72
75
case $opt in
73
76
74
77
# #
@@ -83,6 +86,10 @@ cdc() {
83
86
# -C: Disable color.
84
87
C) use_color=false ;;
85
88
89
+ # #
90
+ # -g: Display git status for each repo.
91
+ g) cdc_git_status=true ;;
92
+
86
93
# #
87
94
# -n: cd to the root of the current repository in the stack.
88
95
n) cdc_current=true ;;
@@ -236,6 +243,8 @@ cdc() {
236
243
echo ' | List all directories that are to be ignored.'
237
244
printf " ${CDC_WARNING_COLOR} -d${CDC_RESET} "
238
245
echo ' | List the directories in stack.'
246
+ printf " ${CDC_WARNING_COLOR} -g${CDC_RESET} "
247
+ echo ' | Cycle through all repositories and print git status.'
239
248
printf " ${CDC_WARNING_COLOR} -n${CDC_RESET} "
240
249
echo ' | `cd` to the current directory in the stack.'
241
250
printf " ${CDC_WARNING_COLOR} -p${CDC_RESET} "
@@ -262,6 +271,34 @@ cdc() {
262
271
return 0
263
272
fi
264
273
274
+ if $cdc_git_status ; then
275
+ if $debug ; then
276
+ _cdc_print ' success' ' Showing git status' $debug
277
+ fi
278
+ dir=" $PWD "
279
+ for directory in " ${CDC_DIRS[@]} " ; do
280
+ [[ -d $directory ]] || continue
281
+ pushd " $directory " > /dev/null
282
+ for subdir in * /; do
283
+ if ! $allow_ignored && _cdc_is_excluded_dir " $subdir " ; then
284
+ continue
285
+ fi
286
+ [[ -d $subdir /.git ]] || continue
287
+ pushd " $subdir " > /dev/null
288
+ if [[ $( git diff --shortstat 2> /dev/null | tail -n1 ) != " " ]]; then
289
+ dirty+=(" $subdir " )
290
+ fi
291
+ popd > /dev/null
292
+ done
293
+ popd > /dev/null
294
+ done
295
+ if (( ${# dirty} > 0 )) ; then
296
+ echo " The following repositories have changes."
297
+ printf " %s\n" " ${dirty[@]} "
298
+ fi
299
+ should_return=true
300
+ fi
301
+
265
302
if $cdc_list_searched_dirs ; then
266
303
if $debug ; then
267
304
_cdc_print ' success' ' Listing searched directories.' $debug
0 commit comments