aboutsummaryrefslogtreecommitdiffstats
path: root/tools/fs_write.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/fs_write.sh')
-rwxr-xr-xtools/fs_write.sh23
1 files changed, 18 insertions, 5 deletions
diff --git a/tools/fs_write.sh b/tools/fs_write.sh
index 7718b8d..59ee812 100755
--- a/tools/fs_write.sh
+++ b/tools/fs_write.sh
@@ -6,15 +6,28 @@ set -e
# If the file doesn't exist, it will be created.
# Always provide the full intended contents of the file.
-# @env FS_BASE_DIR=. The base dir
# @option --path! The path of the file to write to
# @option --contents! The full contents to write to the file
main() {
- path="$FS_BASE_DIR/$argc_path"
- mkdir -p "$(dirname "$path")"
- printf "%s" "$argc_contents" > "$path"
- echo "The contents written to: $path" >> "$LLM_OUTPUT"
+ _guard_path "$argc_path" Write
+ mkdir -p "$(dirname "$argc_path")"
+ printf "%s" "$argc_contents" > "$argc_path"
+ echo "The contents written to: $argc_path" >> "$LLM_OUTPUT"
+}
+
+_guard_path() {
+ path="$(realpath "$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" "$@")"