- Added system detection logic to handle different OS types (Linux, macOS, Windows). - Enhanced user creation logic to support non-root execution and proper ownership. - Updated directory creation to use dynamic home paths based on detected OS. - Improved Git configuration and metadata capture with error handling. - Modularized system package installation based on OS type. - Streamlined Node.js, Python, and Rust setup scripts with error handling. - Updated shell configuration to include dynamic aliases and environment info script. - Deprecated `devcontainer_image` variable in favor of `devcontainer_repo_url` for better repository management. - Adjusted Terraform workspace configuration to support new repository URL and caching options.
280 lines
12 KiB
Bash
280 lines
12 KiB
Bash
#!/bin/bash
|
|
# Convert CRLF to LF if present (handles Windows line endings)
|
|
if command -v dos2unix >/dev/null 2>&1; then
|
|
dos2unix "$0" 2>/dev/null || true
|
|
fi
|
|
|
|
set -e
|
|
echo "🌊 Setting up Windsurf IDE support..."
|
|
|
|
# Cross-platform user and directory detection
|
|
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
|
|
HOME_DIR="${USERPROFILE:-$HOME}"
|
|
USER_NAME="${USERNAME:-${USER:-coder}}"
|
|
WINDSURF_DIR="$HOME_DIR/.windsurf"
|
|
else
|
|
HOME_DIR="${HOME:-/home/coder}"
|
|
USER_NAME="${USER:-coder}"
|
|
WINDSURF_DIR="$HOME_DIR/.windsurf"
|
|
fi
|
|
|
|
# Create Windsurf configuration directories
|
|
mkdir -p "$WINDSURF_DIR/data/User"
|
|
mkdir -p "$WINDSURF_DIR/extensions"
|
|
|
|
# Create optimized Windsurf settings using printf to ensure LF line endings
|
|
{
|
|
printf '{\n'
|
|
printf ' "workbench.colorTheme": "Windsurf Dark",\n'
|
|
printf ' "editor.fontSize": 14,\n'
|
|
printf ' "editor.tabSize": 2,\n'
|
|
printf ' "editor.insertSpaces": true,\n'
|
|
printf ' "editor.formatOnSave": true,\n'
|
|
printf ' "editor.codeActionsOnSave": {\n'
|
|
printf ' "source.fixAll": true,\n'
|
|
printf ' "source.organizeImports": true\n'
|
|
printf ' },\n'
|
|
printf ' "files.autoSave": "afterDelay",\n'
|
|
printf ' "files.autoSaveDelay": 1000,\n'
|
|
printf ' "terminal.integrated.fontSize": 13,\n'
|
|
printf ' "git.enableSmartCommit": true,\n'
|
|
printf ' "git.confirmSync": false,\n'
|
|
printf ' "python.defaultInterpreterPath": "%s/.venv/bin/python",\n' "$HOME_DIR"
|
|
printf ' "python.linting.enabled": true,\n'
|
|
printf ' "python.linting.pylintEnabled": false,\n'
|
|
printf ' "python.linting.flake8Enabled": true,\n'
|
|
printf ' "typescript.preferences.includePackageJsonAutoImports": "auto",\n'
|
|
printf ' "javascript.preferences.includePackageJsonAutoImports": "auto",\n'
|
|
printf ' "windsurf.ai.enabled": true,\n'
|
|
printf ' "windsurf.ai.showInEditorContextMenu": true,\n'
|
|
printf ' "windsurf.chat.enabled": true,\n'
|
|
printf ' "windsurf.codeCompletion.enabled": true\n'
|
|
printf '}\n'
|
|
} > "$WINDSURF_DIR/data/User/settings.json"
|
|
|
|
# Create development keybindings using printf
|
|
{
|
|
printf '[\n'
|
|
printf ' {\n'
|
|
printf ' "key": "ctrl+shift+a",\n'
|
|
printf ' "command": "windsurf.chat.open"\n'
|
|
printf ' },\n'
|
|
printf ' {\n'
|
|
printf ' "key": "ctrl+shift+c",\n'
|
|
printf ' "command": "windsurf.ai.generateCode"\n'
|
|
printf ' },\n'
|
|
printf ' {\n'
|
|
printf ' "key": "ctrl+shift+r",\n'
|
|
printf ' "command": "windsurf.ai.refactorSelection"\n'
|
|
printf ' },\n'
|
|
printf ' {\n'
|
|
printf ' "key": "ctrl+shift+e",\n'
|
|
printf ' "command": "windsurf.ai.explainCode"\n'
|
|
printf ' }\n'
|
|
printf ']\n'
|
|
} > "$WINDSURF_DIR/data/User/keybindings.json"
|
|
|
|
# Create development tasks configuration for Windsurf
|
|
{
|
|
printf '{\n'
|
|
printf ' "version": "2.0.0",\n'
|
|
printf ' "tasks": [\n'
|
|
printf ' {\n'
|
|
printf ' "label": "Dev Server",\n'
|
|
printf ' "type": "shell",\n'
|
|
printf ' "command": "npm run dev",\n'
|
|
printf ' "group": "build",\n'
|
|
printf ' "presentation": {\n'
|
|
printf ' "echo": true,\n'
|
|
printf ' "reveal": "always",\n'
|
|
printf ' "focus": false,\n'
|
|
printf ' "panel": "new"\n'
|
|
printf ' },\n'
|
|
printf ' "problemMatcher": []\n'
|
|
printf ' },\n'
|
|
printf ' {\n'
|
|
printf ' "label": "Python Dev Server",\n'
|
|
printf ' "type": "shell",\n'
|
|
printf ' "command": "uvicorn main:app --reload --host 0.0.0.0 --port 8000",\n'
|
|
printf ' "group": "build",\n'
|
|
printf ' "presentation": {\n'
|
|
printf ' "echo": true,\n'
|
|
printf ' "reveal": "always",\n'
|
|
printf ' "focus": false,\n'
|
|
printf ' "panel": "new"\n'
|
|
printf ' },\n'
|
|
printf ' "problemMatcher": []\n'
|
|
printf ' },\n'
|
|
printf ' {\n'
|
|
printf ' "label": "AI Code Review",\n'
|
|
printf ' "type": "shell",\n'
|
|
printf ' "command": "echo",\n'
|
|
printf ' "args": ["Use Ctrl+Shift+R to refactor selection with Windsurf AI"],\n'
|
|
printf ' "group": "build",\n'
|
|
printf ' "presentation": {\n'
|
|
printf ' "echo": true,\n'
|
|
printf ' "reveal": "always",\n'
|
|
printf ' "focus": false,\n'
|
|
printf ' "panel": "new"\n'
|
|
printf ' }\n'
|
|
printf ' },\n'
|
|
printf ' {\n'
|
|
printf ' "label": "Install Dependencies",\n'
|
|
printf ' "type": "shell",\n'
|
|
printf ' "command": "npm install",\n'
|
|
printf ' "group": "build",\n'
|
|
printf ' "presentation": {\n'
|
|
printf ' "echo": true,\n'
|
|
printf ' "reveal": "always",\n'
|
|
printf ' "focus": false,\n'
|
|
printf ' "panel": "new"\n'
|
|
printf ' }\n'
|
|
printf ' }\n'
|
|
printf ' ]\n'
|
|
printf '}\n'
|
|
} > "$WINDSURF_DIR/data/User/tasks.json"
|
|
|
|
# Create useful code snippets for Windsurf
|
|
mkdir -p "$WINDSURF_DIR/data/User/snippets"
|
|
{
|
|
printf '{\n'
|
|
printf ' "Windsurf AI Comment": {\n'
|
|
printf ' "prefix": "ai-comment",\n'
|
|
printf ' "body": [\n'
|
|
printf ' "// AI-assisted code: ${1:description}",\n'
|
|
printf ' "// Generated with Windsurf AI on $(date)"\n'
|
|
printf ' ],\n'
|
|
printf ' "description": "Add AI assistance comment"\n'
|
|
printf ' },\n'
|
|
printf ' "FastAPI with AI Comments": {\n'
|
|
printf ' "prefix": "fastapi-ai",\n'
|
|
printf ' "body": [\n'
|
|
printf ' "# AI-enhanced FastAPI application",\n'
|
|
printf ' "from fastapi import FastAPI",\n'
|
|
printf ' "from fastapi.middleware.cors import CORSMiddleware",\n'
|
|
printf ' "",\n'
|
|
printf ' "app = FastAPI(",\n'
|
|
printf ' " title=\\"${1:AI-Enhanced API}\\",",\n'
|
|
printf ' " description=\\"API built with Windsurf AI assistance\\",",\n'
|
|
printf ' " version=\\"0.1.0\\"",\n'
|
|
printf ' ")",\n'
|
|
printf ' "",\n'
|
|
printf ' "# AI-suggested CORS configuration",\n'
|
|
printf ' "app.add_middleware(",\n'
|
|
printf ' " CORSMiddleware,",\n'
|
|
printf ' " allow_origins=[\\"*\\"],",\n'
|
|
printf ' " allow_credentials=True,",\n'
|
|
printf ' " allow_methods=[\\"*\\"],",\n'
|
|
printf ' " allow_headers=[\\"*\\"],",\n'
|
|
printf ' ")",\n'
|
|
printf ' "",\n'
|
|
printf ' "@app.get(\\"\/\\")\\",\n'
|
|
printf ' "async def root():",\n'
|
|
printf ' " return {\\"message\\": \\"${2:Hello from AI-enhanced API}\\"}"\n'
|
|
printf ' ],\n'
|
|
printf ' "description": "AI-enhanced FastAPI template"\n'
|
|
printf ' },\n'
|
|
printf ' "React Component with AI": {\n'
|
|
printf ' "prefix": "react-ai",\n'
|
|
printf ' "body": [\n'
|
|
printf ' "// AI-enhanced React component",\n'
|
|
printf ' "import React, { useState, useEffect } from '\''react'\'';",\n'
|
|
printf ' "",\n'
|
|
printf ' "interface ${1:Component}Props {",\n'
|
|
printf ' " // AI-suggested props",\n'
|
|
printf ' " title?: string;",\n'
|
|
printf ' "}",\n'
|
|
printf ' "",\n'
|
|
printf ' "const ${1:Component}: React.FC<${1:Component}Props> = ({ title = '\''${2:Default Title}'\'' }) => {",\n'
|
|
printf ' " const [state, setState] = useState<string>('\'\'');",\n'
|
|
printf ' "",\n'
|
|
printf ' " // AI-suggested useEffect",\n'
|
|
printf ' " useEffect(() => {",\n'
|
|
printf ' " // Component initialization",\n'
|
|
printf ' " }, []);",\n'
|
|
printf ' "",\n'
|
|
printf ' " return (",\n'
|
|
printf ' " <div>",\n'
|
|
printf ' " <h1>{title}</h1>",\n'
|
|
printf ' " {/* AI-enhanced component content */}",\n'
|
|
printf ' " </div>",\n'
|
|
printf ' " );",\n'
|
|
printf ' "};",\n'
|
|
printf ' "",\n'
|
|
printf ' "export default ${1:Component};"\n'
|
|
printf ' ],\n'
|
|
printf ' "description": "AI-enhanced React component template"\n'
|
|
printf ' }\n'
|
|
printf '}\n'
|
|
} > "$WINDSURF_DIR/data/User/snippets/windsurf-ai.code-snippets"
|
|
|
|
# Create Windsurf-specific launch configuration
|
|
{
|
|
printf '{\n'
|
|
printf ' "version": "0.2.0",\n'
|
|
printf ' "configurations": [\n'
|
|
printf ' {\n'
|
|
printf ' "name": "Debug Node.js with AI",\n'
|
|
printf ' "type": "node",\n'
|
|
printf ' "request": "launch",\n'
|
|
printf ' "program": "${workspaceFolder}/index.js",\n'
|
|
printf ' "console": "integratedTerminal",\n'
|
|
printf ' "internalConsoleOptions": "neverOpen"\n'
|
|
printf ' },\n'
|
|
printf ' {\n'
|
|
printf ' "name": "Debug Python with AI",\n'
|
|
printf ' "type": "python",\n'
|
|
printf ' "request": "launch",\n'
|
|
printf ' "program": "${workspaceFolder}/main.py",\n'
|
|
printf ' "console": "integratedTerminal",\n'
|
|
printf ' "python": "%s/.venv/bin/python"\n' "$HOME_DIR"
|
|
printf ' }\n'
|
|
printf ' ]\n'
|
|
printf '}\n'
|
|
} > "$WINDSURF_DIR/data/User/launch.json"
|
|
|
|
# Set proper ownership (Unix-like systems only)
|
|
if [[ "$OSTYPE" != "msys" && "$OSTYPE" != "cygwin" && "$OSTYPE" != "win32" ]]; then
|
|
if command -v chown >/dev/null 2>&1; then
|
|
chown -R "$USER_NAME:$USER_NAME" "$WINDSURF_DIR" 2>/dev/null || {
|
|
echo "⚠️ Could not set ownership - you may need to run with appropriate permissions"
|
|
}
|
|
fi
|
|
fi
|
|
|
|
# Create Windsurf AI helper script
|
|
{
|
|
printf '#!/bin/bash\n'
|
|
printf '# Windsurf AI Helper Commands\n'
|
|
printf 'echo "🌊 Windsurf AI Assistant Helper"\n'
|
|
printf 'echo "============================"\n'
|
|
printf 'echo ""\n'
|
|
printf 'echo "AI Features:"\n'
|
|
printf 'echo " Ctrl+Shift+A # Open AI Chat"\n'
|
|
printf 'echo " Ctrl+Shift+C # Generate Code with AI"\n'
|
|
printf 'echo " Ctrl+Shift+R # Refactor Selection with AI"\n'
|
|
printf 'echo " Ctrl+Shift+E # Explain Code with AI"\n'
|
|
printf 'echo ""\n'
|
|
printf 'echo "AI-Enhanced Snippets:"\n'
|
|
printf 'echo " ai-comment # Add AI assistance comment"\n'
|
|
printf 'echo " fastapi-ai # FastAPI with AI comments"\n'
|
|
printf 'echo " react-ai # React component with AI"\n'
|
|
printf 'echo ""\n'
|
|
printf 'echo "Configuration Location:"\n'
|
|
printf 'echo " Settings: %s/data/User/settings.json"\n' "$WINDSURF_DIR"
|
|
printf 'echo " Keybindings: %s/data/User/keybindings.json"\n' "$WINDSURF_DIR"
|
|
printf 'echo " Snippets: %s/data/User/snippets/"\n' "$WINDSURF_DIR"
|
|
printf 'echo ""\n'
|
|
printf 'echo "💡 Windsurf AI is enabled with optimized settings for development"\n'
|
|
} > "$WINDSURF_DIR/windsurf-help"
|
|
|
|
# Make helper script executable (Unix-like systems only)
|
|
if [[ "$OSTYPE" != "msys" && "$OSTYPE" != "cygwin" && "$OSTYPE" != "win32" ]]; then
|
|
chmod +x "$WINDSURF_DIR/windsurf-help"
|
|
fi
|
|
|
|
echo "✅ Windsurf IDE support configured"
|
|
echo "🌊 Windsurf AI features enabled with optimized settings"
|
|
echo "⌨️ Keyboard shortcuts: Ctrl+Shift+A (chat), Ctrl+Shift+C (generate), Ctrl+Shift+R (refactor)"
|
|
echo "📁 Configuration stored in: $WINDSURF_DIR/"
|
|
echo "💡 Run '$WINDSURF_DIR/windsurf-help' for quick reference" |