diff options
| author | sigoden <sigoden@gmail.com> | 2024-08-02 23:26:49 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-02 23:26:49 +0800 |
| commit | d66d8938f1f845e92966835f70bc2f97ebb8246b (patch) | |
| tree | e81b6da5ff07f1aeaa1799a314f7850c89e97d1c /tools/fs_write.sh | |
| parent | f5c67b3eff5925e35379760d57f886f705120158 (diff) | |
| download | llm-functions-docker-d66d8938f1f845e92966835f70bc2f97ebb8246b.tar.gz | |
feat: prompt confirmation for fs write operations outside cwd (#90)
Diffstat (limited to 'tools/fs_write.sh')
| -rwxr-xr-x | tools/fs_write.sh | 23 |
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" "$@")" |
