Created
February 12, 2026 13:04
-
-
Save Bendzae/c7284be9412e7a51b30d31a365a5f5dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| if ! command -v git >/dev/null 2>&1; then | |
| echo "git is required but not found in PATH" | |
| exit 1 | |
| fi | |
| if ! command -v gh >/dev/null 2>&1; then | |
| echo "gh is required but not found in PATH" | |
| exit 1 | |
| fi | |
| archived_repos=() | |
| for dir in */; do | |
| [[ -d "$dir" ]] || continue | |
| if [[ -d "$dir/.git" || -f "$dir/.git" ]]; then | |
| if ! origin=$(git -C "$dir" remote get-url origin 2>/dev/null); then | |
| continue | |
| fi | |
| repo="" | |
| case "$origin" in | |
| git@github.com:*) repo="${origin#git@github.com:}" ;; | |
| https://github.com/*) repo="${origin#https://github.com/}" ;; | |
| http://github.com/*) repo="${origin#http://github.com/}" ;; | |
| git://github.com/*) repo="${origin#git://github.com/}" ;; | |
| esac | |
| repo="${repo%.git}" | |
| if [[ -z "$repo" ]]; then | |
| continue | |
| fi | |
| if is_archived=$(gh repo view "$repo" --json isArchived -q .isArchived 2>/dev/null); then | |
| if [[ "$is_archived" == "true" ]]; then | |
| archived_repos+=("${dir%/}") | |
| fi | |
| fi | |
| fi | |
| done | |
| if ((${#archived_repos[@]} == 0)); then | |
| echo "No archived repos found." | |
| exit 0 | |
| fi | |
| echo "Archived repos (will be deleted if confirmed):" | |
| printf ' %s\n' "${archived_repos[@]}" | |
| read -r -p "Delete these folders? [y/N] " confirm | |
| case "${confirm}" in | |
| y|Y|yes|YES) | |
| for repo_dir in "${archived_repos[@]}"; do | |
| rm -rf "$repo_dir" | |
| done | |
| echo "Deleted ${#archived_repos[@]} archived repos." | |
| ;; | |
| *) | |
| echo "Cancelled." | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment