diff options
| author | sigoden <sigoden@gmail.com> | 2024-12-11 08:15:01 +0800 |
|---|---|---|
| committer | sigoden <sigoden@gmail.com> | 2024-12-11 08:15:01 +0800 |
| commit | d8da00d6d61f35892bec09ef002bd0cc9f9a0465 (patch) | |
| tree | 8d9bbb07ddad8a7666da4ddbc0c9c92d7e46429d | |
| parent | 22a87a8753ca1ad23ebe0a816c230302edfd7416 (diff) | |
| download | llm-functions-docker-d8da00d6d61f35892bec09ef002bd0cc9f9a0465.tar.gz | |
feat(tool): fs_write ask confirmation for existing files
| -rwxr-xr-x | tools/fs_write.sh | 9 |
1 files 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" } |
