Skip to content

Commit

Permalink
Add -g for git status
Browse files Browse the repository at this point in the history
  • Loading branch information
evanthegrayt committed May 25, 2021
1 parent 1a13553 commit 170a057
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ overriding variables set in `~/.cdcrc`. There's also a debug mode.
|-C|Disable colored output.|
|-l|List all directories to which you can `cdc`. Same as tab-completion.|
|-L|List the directories in which `cdc` will search.|
|-g|Cycle through all repositories and print the `git status`.|
|-i|List the directories that are to be ignored.|
|-d|List directories in history stack. Similar to the `dirs` command.|
|-n|`cd` to the current directory in the history stack.|
Expand Down
3 changes: 2 additions & 1 deletion cdc.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ _cdc() {
-h"[Print this help.]" \
- no_other_args \
-n"[cd to the current directory in the stack.]" \
-p"[cd to previous directory and pop from the stack]" \
-p"[cd to previous directory and pop from the stack.]" \
-g"[Cycle through all repositories and print git status.]" \
-t"[Toggle between the last two directories in the stack.]" \
-i"[List all directories that are to be ignored.]" \
-l"[List all directories that are cdc-able.]" \
Expand Down
35 changes: 33 additions & 2 deletions cdc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ cdc() {
local dir
local list
local directory
local subdir
local wdir
local marker
local cdc_last_element
Expand All @@ -33,6 +34,7 @@ cdc() {
local which=false
local cdc_current=false
local cdc_pop=false
local cdc_git_status=false
local cdc_show_history=false
local cdc_list_ignored=false
local print_help=false
Expand All @@ -55,7 +57,7 @@ cdc() {
# If argument contains a slash, it's assumed to contain subdirectories.
# This splits them into the directory root and its subdirectories.
if [[ "$1" == */* ]]; then
local subdir="${1#*/}"
subdir="${1#*/}"
fi

##
Expand All @@ -68,7 +70,7 @@ cdc() {

##
# Case options if present. Suppress errors because we'll supply our own.
while getopts 'acCdDhilLnprRstuUw' opt 2>/dev/null; do
while getopts 'acCdDghilLnprRstuUw' opt 2>/dev/null; do
case $opt in

##
Expand All @@ -83,6 +85,10 @@ cdc() {
# -C: Disable color.
C) use_color=false ;;

##
# -g: Display git status for each repo.
g) cdc_git_status=true ;;

##
# -n: cd to the root of the current repository in the stack.
n) cdc_current=true ;;
Expand Down Expand Up @@ -236,6 +242,8 @@ cdc() {
echo ' | List all directories that are to be ignored.'
printf " ${CDC_WARNING_COLOR}-d${CDC_RESET}"
echo ' | List the directories in stack.'
printf " ${CDC_WARNING_COLOR}-g${CDC_RESET}"
echo ' | Cycle through all repositories and print git status.'
printf " ${CDC_WARNING_COLOR}-n${CDC_RESET}"
echo ' | `cd` to the current directory in the stack.'
printf " ${CDC_WARNING_COLOR}-p${CDC_RESET}"
Expand All @@ -262,6 +270,29 @@ cdc() {
return 0
fi

if $cdc_git_status; then
if $debug; then
_cdc_print 'success' 'Showing git status' $debug
fi
dir="$PWD"
for directory in "${CDC_DIRS[@]}"; do
[[ -d $directory ]] || continue
pushd "$directory" >/dev/null
for subdir in */; do
if ! $allow_ignored && _cdc_is_excluded_dir "$subdir"; then
continue
fi
[[ -d $subdir/.git ]] || continue
printf "\n\n>> Checking status of [%s] <<\n" "$subdir"
pushd "$subdir" >/dev/null
git status
popd >/dev/null
done
popd >/dev/null
done
should_return=true
fi

if $cdc_list_searched_dirs; then
if $debug; then
_cdc_print 'success' 'Listing searched directories.' $debug
Expand Down

0 comments on commit 170a057

Please sign in to comment.