cocopilot/cocopilot.sh
jim af1b55aa83 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.
2023-09-05 16:01:59 +08:00

32 lines
797 B
Bash
Executable File

#!/bin/bash
set -e
if [ -n "$XDG_CONFIG_HOME" ]; then
CONFIG_DIR="$XDG_CONFIG_HOME"
else
CONFIG_DIR="$HOME/.config"
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
echo '{"github.com":{"user":"cocopilot","oauth_token":"ghu_ThisIsARealFreeCopilotKeyByCoCopilot","dev_override":{"copilot_token_url":"https://api.cocopilot.org/copilot_internal/v2/token"}}}' > "$COPILOT_DIR/hosts.json"
echo 'done. please restart your ide.'