Skip to content

Commit 2dc27fa

Browse files
committed
Add -g for git status
1 parent 1a13553 commit 2dc27fa

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ overriding variables set in `~/.cdcrc`. There's also a debug mode.
198198
|-C|Disable colored output.|
199199
|-l|List all directories to which you can `cdc`. Same as tab-completion.|
200200
|-L|List the directories in which `cdc` will search.|
201+
|-g|Cycle through all repositories and print the `git status`.|
201202
|-i|List the directories that are to be ignored.|
202203
|-d|List directories in history stack. Similar to the `dirs` command.|
203204
|-n|`cd` to the current directory in the history stack.|

Diff for: cdc.plugin.zsh

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ _cdc() {
1414
-h"[Print this help.]" \
1515
- no_other_args \
1616
-n"[cd to the current directory in the stack.]" \
17-
-p"[cd to previous directory and pop from the stack]" \
17+
-p"[cd to previous directory and pop from the stack.]" \
18+
-g"[Cycle through all repositories and print git status.]" \
1819
-t"[Toggle between the last two directories in the stack.]" \
1920
-i"[List all directories that are to be ignored.]" \
2021
-l"[List all directories that are cdc-able.]" \

Diff for: cdc.sh

+39-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ cdc() {
1818
local dir
1919
local list
2020
local directory
21+
local subdir
2122
local wdir
2223
local marker
2324
local cdc_last_element
2425
local cdc_next_to_last_element
2526
local cdc_history
2627
local rc=0
28+
local dirty=()
2729
local cdc_list_dirs=false
2830
local cdc_list_searched_dirs=false
2931
local cdc_toggle=false
@@ -33,6 +35,7 @@ cdc() {
3335
local which=false
3436
local cdc_current=false
3537
local cdc_pop=false
38+
local cdc_git_status=false
3639
local cdc_show_history=false
3740
local cdc_list_ignored=false
3841
local print_help=false
@@ -55,7 +58,7 @@ cdc() {
5558
# If argument contains a slash, it's assumed to contain subdirectories.
5659
# This splits them into the directory root and its subdirectories.
5760
if [[ "$1" == */* ]]; then
58-
local subdir="${1#*/}"
61+
subdir="${1#*/}"
5962
fi
6063

6164
##
@@ -68,7 +71,7 @@ cdc() {
6871

6972
##
7073
# 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
7275
case $opt in
7376

7477
##
@@ -83,6 +86,10 @@ cdc() {
8386
# -C: Disable color.
8487
C) use_color=false ;;
8588

89+
##
90+
# -g: Display git status for each repo.
91+
g) cdc_git_status=true ;;
92+
8693
##
8794
# -n: cd to the root of the current repository in the stack.
8895
n) cdc_current=true ;;
@@ -236,6 +243,8 @@ cdc() {
236243
echo ' | List all directories that are to be ignored.'
237244
printf " ${CDC_WARNING_COLOR}-d${CDC_RESET}"
238245
echo ' | List the directories in stack.'
246+
printf " ${CDC_WARNING_COLOR}-g${CDC_RESET}"
247+
echo ' | Cycle through all repositories and print git status.'
239248
printf " ${CDC_WARNING_COLOR}-n${CDC_RESET}"
240249
echo ' | `cd` to the current directory in the stack.'
241250
printf " ${CDC_WARNING_COLOR}-p${CDC_RESET}"
@@ -262,6 +271,34 @@ cdc() {
262271
return 0
263272
fi
264273

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+
265302
if $cdc_list_searched_dirs; then
266303
if $debug; then
267304
_cdc_print 'success' 'Listing searched directories.' $debug

0 commit comments

Comments
 (0)