diff --git a/README.md b/README.md index 3778fea..d5fbc1c 100644 --- a/README.md +++ b/README.md @@ -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.| diff --git a/cdc.plugin.zsh b/cdc.plugin.zsh index 331d47a..2dd6dc6 100644 --- a/cdc.plugin.zsh +++ b/cdc.plugin.zsh @@ -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.]" \ diff --git a/cdc.sh b/cdc.sh index 4ccb072..408496a 100644 --- a/cdc.sh +++ b/cdc.sh @@ -18,12 +18,14 @@ cdc() { local dir local list local directory + local subdir local wdir local marker local cdc_last_element local cdc_next_to_last_element local cdc_history local rc=0 + local dirty=() local cdc_list_dirs=false local cdc_list_searched_dirs=false local cdc_toggle=false @@ -33,6 +35,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 @@ -55,7 +58,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 ## @@ -68,7 +71,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 ## @@ -83,6 +86,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 ;; @@ -236,6 +243,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}" @@ -262,6 +271,34 @@ 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 + pushd "$subdir" >/dev/null + if [[ $( git diff --shortstat 2>/dev/null | tail -n1 ) != "" ]]; then + dirty+=("$subdir") + fi + popd >/dev/null + done + popd >/dev/null + done + if (( ${#dirty} > 0 )); then + echo "The following repositories have changes." + printf "%s\n" "${dirty[@]}" + fi + should_return=true + fi + if $cdc_list_searched_dirs; then if $debug; then _cdc_print 'success' 'Listing searched directories.' $debug