Last active
January 9, 2023 16:35
-
-
Save pradyumnac/f572e5e0aa069fb1215bda8cce6ebf3d to your computer and use it in GitHub Desktop.
Github CLI - Delete github repos from terminal
This file contains 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 | |
# BE EXTRA CAREFUL with repo deletion. There is no way to recover repository once its deleted. | |
# Do this AT YOUR OWN RISK | |
# Pre-requisites: gh cli, awk | |
# Selection through file edit | |
# gh repo list -L 100 | awk '{print $1}' | sed 's,.*/,,') > repo.remote.list.all | |
# gh repo list -L 100 --source | awk '{print $1}' | sed 's,.*/,,') > repo.remote.list.all # non forked | |
# Edit this and save as repo.remote.all.delete | |
# declare -a repoarray=( $(cat repo.remote.delete) ) | |
# or | |
# Interactve selection: you need to have gum installed as well | |
repoall=$(gh repo list -L 100 | awk '{print $1}' | sed 's,.*/,,') | |
declare -a repoarray=( $(echo -e "$repoall"|gum filter --no-limit) ) | |
if [[ ${#repoarray[@]} -eq 0 ]]; then echo "Cancelled by user.."; exit 1; fi | |
echo "Deleting ${repoarray[@]}.." | |
echo "################ WARNING ################################################" | |
echo "This process is completely irreversible.. You will permanently loose data" | |
echo "#########################################################################" | |
echo | |
read -p "Are you sure? (y/N)" -n 1 -r | |
echo | |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi | |
for i in "${repoarray[@]}" | |
do | |
echo "Deleting $i .."; | |
gh repo delete $i | |
# gh repo delete $i --confirm; | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment