diff --git a/whatsdirty b/whatsdirty index e0e1805..d5e46cf 100755 --- a/whatsdirty +++ b/whatsdirty @@ -372,8 +372,14 @@ print_clean_repositories() { local temp_file="$1" if grep -q "^C|" "$temp_file" 2>/dev/null; then - printf "\n=== CLEAN REPOSITORIES ===\n\n" - grep "^C|" "$temp_file" | sort -t'|' -k2,2n | while IFS='|' read -r _ _ changes repo hours_fmt upstream_status upstream_ahead upstream_behind; do + local total_clean + total_clean=$(grep -c "^C|" "$temp_file" 2>/dev/null) + if [ "$total_clean" -gt 5 ]; then + printf "\n=== CLEAN REPOSITORIES (top 5 of %d) ===\n\n" "$total_clean" + else + printf "\n=== CLEAN REPOSITORIES ===\n\n" + fi + grep "^C|" "$temp_file" | sort -t'|' -k2,2n | head -5 | while IFS='|' read -r _ _ changes repo hours_fmt upstream_status upstream_ahead upstream_behind; do local upstream_fmt upstream_fmt=$(format_upstream_status "$upstream_status" "$upstream_ahead" "$upstream_behind") printf "%-40s %15s %-10s %-10s %-12b\n" "$repo" "$hours_fmt" "$changes" "Clean" "$upstream_fmt" @@ -381,6 +387,41 @@ print_clean_repositories() { fi } +# === Interactive Functions === + +offer_gp_dirty_repos() { + local temp_file="$1" + local base_dir="$2" + + # Collect dirty repo names + local -a dirty_repos=() + while IFS='|' read -r type _ _ repo _; do + dirty_repos+=("$repo") + done < <(grep "^D|" "$temp_file" 2>/dev/null | sort -t'|' -k3,3nr) + + if [ ${#dirty_repos[@]} -eq 0 ]; then + return + fi + + printf "\n" + for repo in "${dirty_repos[@]}"; do + local repo_path="${base_dir}/${repo}" + printf "Run 'gp -y' in ${RED}%s${NC}? [y/N/q] " "$repo" + read -r answer