aboutsummaryrefslogtreecommitdiffstats
path: root/tools/fs_rm.sh
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-08-02 23:26:49 +0800
committerGitHub <noreply@github.com>2024-08-02 23:26:49 +0800
commitd66d8938f1f845e92966835f70bc2f97ebb8246b (patch)
treee81b6da5ff07f1aeaa1799a314f7850c89e97d1c /tools/fs_rm.sh
parentf5c67b3eff5925e35379760d57f886f705120158 (diff)
downloadllm-functions-docker-d66d8938f1f845e92966835f70bc2f97ebb8246b.tar.gz
feat: prompt confirmation for fs write operations outside cwd (#90)
Diffstat (limited to 'tools/fs_rm.sh')
-rwxr-xr-xtools/fs_rm.sh22
1 files changed, 19 insertions, 3 deletions
diff --git a/tools/fs_rm.sh b/tools/fs_rm.sh
index 1d40295..c07c17d 100755
--- a/tools/fs_rm.sh
+++ b/tools/fs_rm.sh
@@ -7,9 +7,25 @@ set -e
# @option --path! The path of the file or directory to remove
main() {
- path="$FS_BASE_DIR/$argc_path"
- rm -rf "$path"
- echo "Path removed: $path" >> "$LLM_OUTPUT"
+ if [[ -f "$argc_path" ]]; then
+ _guard_path "$argc_path" Remove
+ rm -rf "$argc_path"
+ fi
+ echo "Path removed: $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" "$@")"