aboutsummaryrefslogtreecommitdiffstats
path: root/tools/fs_write.sh
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-11-16 11:09:40 +0800
committerGitHub <noreply@github.com>2024-11-16 11:09:40 +0800
commit86aa9106090a0219bac30bc12f5a5bd91949afd9 (patch)
tree69aef8c03242c67480c4edfe42a2cbf4c785b466 /tools/fs_write.sh
parent6d30c22b82a5ac1a5775d8137c3b08a581770273 (diff)
downloadllm-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_write.sh')
-rwxr-xr-xtools/fs_write.sh18
1 files changed, 3 insertions, 15 deletions
diff --git a/tools/fs_write.sh b/tools/fs_write.sh
index 0e0dba0..303a77b 100755
--- a/tools/fs_write.sh
+++ b/tools/fs_write.sh
@@ -8,25 +8,13 @@ set -e
# @env LLM_OUTPUT=/dev/stdout The output path
+ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
+
main() {
- _guard_path "$argc_path" Write
+ "$ROOT_DIR/utils/guard_path.sh" "$argc_path" "Write '$argc_path'?"
mkdir -p "$(dirname "$argc_path")"
printf "%s" "$argc_contents" > "$argc_path"
echo "The contents written to: $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" "$@")"