#!/bin/bash

prog=${0##*/}
progdir=${0%/*}

fail () {
    echo "$prog:" "$@" >&2
    exit 1
}

is_true () {
    case "${1-}" in
        [yY]*|[tT]*|1) return 0 ;;
        [nN]*|[fF]*|0) return 1 ;;
    esac
    return 2  # unknown
}

ask_yn () {
    local yn
    echo "$@" >&2
    while true; do
        read yn
        case $yn in
            [Yy]*) return 0;;
            [Nn]*) return 1;;
            *) echo Enter yes or no >&2;;
        esac
    done
}

set -uo pipefail
IFS=$'\n\t'
is_true "${DEBUG-}" && export PS4='${LINENO}: ' && set -x  # https://stackoverflow.com/a/17805088

find . -type d -name .backup -o -name .bak
if ask_yn ok?; then
    find . \( -type d -name .backup -o -name .bak \) -exec rm -rf '{}' +
fi

# vim:et:sw=4:sts=4:ts=8
