aboutsummaryrefslogtreecommitdiffstats
path: root/utils/guard_operation.sh
blob: 1e7f1ede3ad61121701a150b417b93ef8b470b55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env bash

# Guard an operation with a confirmation prompt.

main() {
    if [ -t 1 ]; then
        confirmation_prompt="${1:-"Are you sure you want to continue?"}"
        read -r -p "$confirmation_prompt [Y/n] " ans
        if [[ "$ans" == "N" || "$ans" == "n" ]]; then
            echo "error: aborted!" 2>&1
            exit 1
        fi
    fi
}

main "$@"