feat: prompt confirmation for fs write operations outside cwd (#90)

This commit is contained in:
sigoden
2024-08-02 23:26:49 +08:00
committed by GitHub
parent f5c67b3eff
commit d66d8938f1
6 changed files with 63 additions and 28 deletions
+18 -5
View File
@@ -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" "$@")"