Skip to content

Instantly share code, notes, and snippets.

@Bendzae
Created February 12, 2026 13:04
Show Gist options
  • Select an option

  • Save Bendzae/c7284be9412e7a51b30d31a365a5f5dc to your computer and use it in GitHub Desktop.

Select an option

Save Bendzae/c7284be9412e7a51b30d31a365a5f5dc to your computer and use it in GitHub Desktop.
#!/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