From af1b55aa83811fd9ee354cec4741fb23b83597e5 Mon Sep 17 00:00:00 2001 From: jim Date: Tue, 5 Sep 2023 16:01:59 +0800 Subject: [PATCH] Add User Confirmation Before Overwriting Files - Implement a check to see if the target file already exists - Prompt the user to confirm if they want to overwrite the existing file - Exit the script if the user opts not to overwrite This change improves the user experience by providing a safety measure to prevent accidental file overwriting. --- cocopilot.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cocopilot.sh b/cocopilot.sh index a7ab7a9..e59187e 100755 --- a/cocopilot.sh +++ b/cocopilot.sh @@ -9,6 +9,19 @@ else fi COPILOT_DIR="$CONFIG_DIR/github-copilot" + +# Check if the target file already exists +TARGET_FILE="$COPILOT_DIR/hosts.json" + +if [ -f "$TARGET_FILE" ]; then + read -p "The file $TARGET_FILE already exists. Do you want to overwrite it? [y/N] " -r + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Operation cancelled." + exit 1 + fi +fi + +# Create directory if [ ! -d "$COPILOT_DIR" ]; then mkdir -p "$COPILOT_DIR" fi