Skip to content

Instantly share code, notes, and snippets.

@NathanUrwin
Last active March 15, 2018 19:14
Show Gist options
  • Save NathanUrwin/b837e04ffe4cf1e63735446967b6966e to your computer and use it in GitHub Desktop.
Save NathanUrwin/b837e04ffe4cf1e63735446967b6966e to your computer and use it in GitHub Desktop.
git() {
bold="$(tput bold)"
black="$(tput setaf 0)"
red="$(tput setab 1)"
yellow="$(tput setab 3)"
cyan="$(tput setaf 6)"
reset="$(tput sgr0)"
if [ "$1" != delete ]; then
hub "$@"
return
fi
if [ -z "$3" ]; then
echo 'No repository slug or repository namespace given.'
return 1
fi
if ! command -v gcli &> /dev/null; then
echo 'gcli is not available. run: gem install github_cli'
return 1
fi
GCLI_USER="$(gcli config user.login)"
if [ -z "$GCLI_USER" ]; then
echo 'gcli user.login config is not set. see: gcli help config'
return 1
fi
echo
echo 'Are you ABSOLUTELY sure?'
echo
echo "${yellow}${black} ${reset}"
echo "${yellow}${black} Unexpected bad things will happen if you don't read this! ${reset}"
echo "${yellow}${black} ${reset}"
echo
echo "This action ${bold}CANNOT${reset} be undone. This will permanently delete the"
echo "${bold}${2}/${3}${reset} repository, wiki, issues,"
echo 'and comments, and remove all team associations.'
echo
read -p "$(echo -e 'Please type in the name of the repository to confirm.\n\b')"
echo
if [[ "$REPLY" == "${2}/${3}" ]]; then
whitespace=' '
read -p "$(echo -e "${red} ${whitespace} ${reset}\n${bold}${red} I understand the consequences, delete this repository ${reset}\n${red} ${whitespace} ${reset} ${bold}[yN]${reset}")" -n 1
echo
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
success="$(gcli repo "$@")"
if [[ "$success" =~ 204 ]]; then
echo
echo "${cyan}Your repository \"${2}/${3}\" was successfully deleted.${reset}"
echo
fi
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment