From d8da00d6d61f35892bec09ef002bd0cc9f9a0465 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 11 Dec 2024 08:15:01 +0800 Subject: feat(tool): fs_write ask confirmation for existing files --- tools/fs_write.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/fs_write.sh b/tools/fs_write.sh index 303a77b..e418835 100755 --- a/tools/fs_write.sh +++ b/tools/fs_write.sh @@ -11,8 +11,13 @@ set -e ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" main() { - "$ROOT_DIR/utils/guard_path.sh" "$argc_path" "Write '$argc_path'?" - mkdir -p "$(dirname "$argc_path")" + if [[ -f "$argc_path" ]]; then + printf "%s" "$argc_contents" | git diff --no-index "$argc_path" - || true + "$ROOT_DIR/utils/guard_operation.sh" "Apply changes?" + else + "$ROOT_DIR/utils/guard_path.sh" "$argc_path" "Write '$argc_path'?" + mkdir -p "$(dirname "$argc_path")" + fi printf "%s" "$argc_contents" > "$argc_path" echo "The contents written to: $argc_path" >> "$LLM_OUTPUT" } -- cgit v1.2.3