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 /tools/fs_patch.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 'tools/fs_patch.sh')
| -rwxr-xr-x | tools/fs_patch.sh | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/tools/fs_patch.sh b/tools/fs_patch.sh index 14e46d2..ce71628 100755 --- a/tools/fs_patch.sh +++ b/tools/fs_patch.sh @@ -18,22 +18,16 @@ 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 echo "Not found file: $argc_path" exit 1 fi - root_dir="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" - new_contents="$(awk -f "$root_dir/utils/patch.awk" "$argc_path" <(printf "%s" "$argc_contents"))" + new_contents="$(awk -f "$ROOT_DIR/utils/patch.awk" "$argc_path" <(printf "%s" "$argc_contents"))" printf "%s" "$new_contents" | git diff --no-index "$argc_path" - || true - if [ -t 1 ]; then - echo - read -r -p "Apply changes? [Y/n] " ans - if [[ "$ans" == "N" || "$ans" == "n" ]]; then - echo "Aborted!" - exit 1 - fi - fi + "$ROOT_DIR/utils/guard_operation.sh" "Apply changes?" printf "%s" "$new_contents" > "$argc_path" echo "The patch applied to: $argc_path" >> "$LLM_OUTPUT" |
