From 86aa9106090a0219bac30bc12f5a5bd91949afd9 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 16 Nov 2024 11:09:40 +0800 Subject: refactor: improve bash code (#125) * refactor: extract guard_path to utils/guard_path.sh * add utils/guard_operation.sh --- tools/fs_rm.sh | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'tools/fs_rm.sh') diff --git a/tools/fs_rm.sh b/tools/fs_rm.sh index dd1e2f7..9d9386f 100755 --- a/tools/fs_rm.sh +++ b/tools/fs_rm.sh @@ -7,26 +7,14 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path +ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" + main() { if [[ -f "$argc_path" ]]; then - _guard_path "$argc_path" Remove + "$ROOT_DIR/utils/guard_path.sh" "$argc_path" "Remove '$argc_path'?" rm -rf "$argc_path" fi echo "Path removed: $argc_path" >> "$LLM_OUTPUT" } -_guard_path() { - path="$(realpath -m "$1")" - action="$2" - if [[ ! "$path" == "$(pwd)"* ]]; then - if [ -t 1 ]; then - read -r -p "$action $path? [Y/n] " ans - if [[ "$ans" == "N" || "$ans" == "n" ]]; then - echo "Aborted!" - exit 1 - fi - fi - fi -} - eval "$(argc --argc-eval "$0" "$@")" -- cgit v1.2.3