Skip to content

Commit 170a057

Browse files
committed
Add -g for git status
1 parent 1a13553 commit 170a057

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
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.|

cdc.plugin.zsh

Lines changed: 2 additions & 1 deletion
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.]" \

cdc.sh

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cdc() {
1818
local dir
1919
local list
2020
local directory
21+
local subdir
2122
local wdir
2223
local marker
2324
local cdc_last_element
@@ -33,6 +34,7 @@ cdc() {
3334
local which=false
3435
local cdc_current=false
3536
local cdc_pop=false
37+
local cdc_git_status=false
3638
local cdc_show_history=false
3739
local cdc_list_ignored=false
3840
local print_help=false
@@ -55,7 +57,7 @@ cdc() {
5557
# If argument contains a slash, it's assumed to contain subdirectories.
5658
# This splits them into the directory root and its subdirectories.
5759
if [[ "$1" == */* ]]; then
58-
local subdir="${1#*/}"
60+
subdir="${1#*/}"
5961
fi
6062

6163
##
@@ -68,7 +70,7 @@ cdc() {
6870

6971
##
7072
# Case options if present. Suppress errors because we'll supply our own.
71-
while getopts 'acCdDhilLnprRstuUw' opt 2>/dev/null; do
73+
while getopts 'acCdDghilLnprRstuUw' opt 2>/dev/null; do
7274
case $opt in
7375

7476
##
@@ -83,6 +85,10 @@ cdc() {
8385
# -C: Disable color.
8486
C) use_color=false ;;
8587

88+
##
89+
# -g: Display git status for each repo.
90+
g) cdc_git_status=true ;;
91+
8692
##
8793
# -n: cd to the root of the current repository in the stack.
8894
n) cdc_current=true ;;
@@ -236,6 +242,8 @@ cdc() {
236242
echo ' | List all directories that are to be ignored.'
237243
printf " ${CDC_WARNING_COLOR}-d${CDC_RESET}"
238244
echo ' | List the directories in stack.'
245+
printf " ${CDC_WARNING_COLOR}-g${CDC_RESET}"
246+
echo ' | Cycle through all repositories and print git status.'
239247
printf " ${CDC_WARNING_COLOR}-n${CDC_RESET}"
240248
echo ' | `cd` to the current directory in the stack.'
241249
printf " ${CDC_WARNING_COLOR}-p${CDC_RESET}"
@@ -262,6 +270,29 @@ cdc() {
262270
return 0
263271
fi
264272

273+
if $cdc_git_status; then
274+
if $debug; then
275+
_cdc_print 'success' 'Showing git status' $debug
276+
fi
277+
dir="$PWD"
278+
for directory in "${CDC_DIRS[@]}"; do
279+
[[ -d $directory ]] || continue
280+
pushd "$directory" >/dev/null
281+
for subdir in */; do
282+
if ! $allow_ignored && _cdc_is_excluded_dir "$subdir"; then
283+
continue
284+
fi
285+
[[ -d $subdir/.git ]] || continue
286+
printf "\n\n>> Checking status of [%s] <<\n" "$subdir"
287+
pushd "$subdir" >/dev/null
288+
git status
289+
popd >/dev/null
290+
done
291+
popd >/dev/null
292+
done
293+
should_return=true
294+
fi
295+
265296
if $cdc_list_searched_dirs; then
266297
if $debug; then
267298
_cdc_print 'success' 'Listing searched directories.' $debug

0 commit comments

Comments
 (0)