commit 7afbde68cac22f2a9f6dce231f1048d87e07d411
parent 44f89f89c0f38328c44dd52bb1c1b4ec4846c580
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Fri, 28 Oct 2022 18:27:39 -0400
Add confirmation prompt in case something will be overwritten
This stops the user from accidentally overwriting a file full of content
or resetting a website directory when using commands such as 'sbs new
page' or 'sbs new site'.
Diffstat:
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/sbs b/sbs
@@ -26,6 +26,16 @@ new()
exit 1
fi
+ if [ -e "$3" ]; then
+ printf "%s already exists. Doing this will overwrite it.\n" "$3"
+ printf "Are you sure you want to overwrite it? (y/N): "
+ read input
+ input=$(echo "$input" | tr "[:upper:]" "[:lower:]")
+ if [ "$input" != "y" ] && [ "$input" != "yes" ]; then
+ return
+ fi
+ fi
+
if [ "$2" = "page" ]; then
{ printf "Title: \nSummary: \n\n"
printf "# [%%title]\n\n"