diff options
| author | sigoden <sigoden@gmail.com> | 2024-11-16 11:09:40 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-16 11:09:40 +0800 |
| commit | 86aa9106090a0219bac30bc12f5a5bd91949afd9 (patch) | |
| tree | 69aef8c03242c67480c4edfe42a2cbf4c785b466 /utils/guard_operation.sh | |
| parent | 6d30c22b82a5ac1a5775d8137c3b08a581770273 (diff) | |
| download | llm-functions-docker-86aa9106090a0219bac30bc12f5a5bd91949afd9.tar.gz | |
refactor: improve bash code (#125)
* refactor: extract guard_path to utils/guard_path.sh
* add utils/guard_operation.sh
Diffstat (limited to 'utils/guard_operation.sh')
| -rwxr-xr-x | utils/guard_operation.sh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/utils/guard_operation.sh b/utils/guard_operation.sh new file mode 100755 index 0000000..1e7f1ed --- /dev/null +++ b/utils/guard_operation.sh @@ -0,0 +1,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 "$@" |
