mirror of
https://github.com/pengzhile/cocopilot.git
synced 2025-01-19 03:25:51 +08:00
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.
This commit is contained in:
parent
f7d7a32000
commit
af1b55aa83
13
cocopilot.sh
13
cocopilot.sh
@ -9,6 +9,19 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
COPILOT_DIR="$CONFIG_DIR/github-copilot"
|
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
|
if [ ! -d "$COPILOT_DIR" ]; then
|
||||||
mkdir -p "$COPILOT_DIR"
|
mkdir -p "$COPILOT_DIR"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user