Files
code-tools/tf/scripts/cursor-setup.sh
Travis Vasceannie bb469f8d2b Refactor workspace setup script for cross-platform compatibility and improved user management
- 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.
2025-09-07 20:56:56 +00:00

203 lines
8.7 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 Cursor 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}}"
CURSOR_DIR="$HOME_DIR/.cursor-server"
else
HOME_DIR="${HOME:-/home/coder}"
USER_NAME="${USER:-coder}"
CURSOR_DIR="$HOME_DIR/.cursor-server"
fi
# Create Cursor configuration directories
mkdir -p "$CURSOR_DIR/data/User"
mkdir -p "$CURSOR_DIR/extensions"
# Create optimized Cursor settings using printf to ensure LF line endings
{
printf '{\n'
printf ' "workbench.colorTheme": "Dark+ (default 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 ' "cursor.chat.showInEditorContextMenu": true,\n'
printf ' "cursor.chat.alwaysShowInEditorContextMenu": true,\n'
printf ' "cursor.general.enableWindowAIFeatures": true\n'
printf '}\n'
} > "$CURSOR_DIR/data/User/settings.json"
# Create development tasks configuration
{
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": "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 ' "label": "Python Install",\n'
printf ' "type": "shell",\n'
printf ' "command": "uv pip install -r requirements.txt",\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'
} > "$CURSOR_DIR/data/User/tasks.json"
# Create useful code snippets
mkdir -p "$CURSOR_DIR/data/User/snippets"
{
printf '{\n'
printf ' "FastAPI Basic App": {\n'
printf ' "prefix": "fastapi-app",\n'
printf ' "body": [\n'
printf ' "from fastapi import FastAPI",\n'
printf ' "from fastapi.middleware.cors import CORSMiddleware",\n'
printf ' "",\n'
printf ' "app = FastAPI(title=\\"${1:My API}\\", version=\\"0.1.0\\")",\n'
printf ' "",\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 World}\\"}",\n'
printf ' "",\n'
printf ' "@app.get(\\"\/health\\")",\n'
printf ' "async def health():",\n'
printf ' " return {\\"status\\": \\"healthy\\"}",\n'
printf ' "",\n'
printf ' "if __name__ == \\"__main__\\":",\n'
printf ' " import uvicorn",\n'
printf ' " uvicorn.run(app, host=\\"0.0.0.0\\", port=8000)"\n'
printf ' ],\n'
printf ' "description": "FastAPI basic application template"\n'
printf ' },\n'
printf ' "Next.js API Route": {\n'
printf ' "prefix": "nextapi",\n'
printf ' "body": [\n'
printf ' "import { NextRequest, NextResponse } from '\''next\/server'\'';",\n'
printf ' "",\n'
printf ' "export async function ${1:GET}(request: NextRequest) {",\n'
printf ' " try {",\n'
printf ' " \/\/ Your API logic here",\n'
printf ' " return NextResponse.json({ message: '\''${2:Success}'\'' });",\n'
printf ' " } catch (error) {",\n'
printf ' " return NextResponse.json(",\n'
printf ' " { error: '\''Internal Server Error'\'' },",\n'
printf ' " { status: 500 }",\n'
printf ' " );",\n'
printf ' " }",\n'
printf ' "}"\n'
printf ' ],\n'
printf ' "description": "Next.js API route template"\n'
printf ' },\n'
printf ' "Database Connection": {\n'
printf ' "prefix": "db-connect",\n'
printf ' "body": [\n'
printf ' "import os",\n'
printf ' "from sqlalchemy import create_engine",\n'
printf ' "from sqlalchemy.orm import sessionmaker",\n'
printf ' "",\n'
printf ' "DATABASE_URL = os.getenv(",\n'
printf ' " \\"POSTGRES_URL\\",",\n'
printf ' " \\"postgresql:\/\/postgres:password@localhost:5432\/postgres\\"",\n'
printf ' ")",\n'
printf ' "",\n'
printf ' "engine = create_engine(DATABASE_URL)",\n'
printf ' "SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)",\n'
printf ' "",\n'
printf ' "def get_db():",\n'
printf ' " db = SessionLocal()",\n'
printf ' " try:",\n'
printf ' " yield db",\n'
printf ' " finally:",\n'
printf ' " db.close()"\n'
printf ' ],\n'
printf ' "description": "Database connection setup"\n'
printf ' }\n'
printf '}\n'
} > "$CURSOR_DIR/data/User/snippets/global.code-snippets"
# 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" "$CURSOR_DIR" 2>/dev/null || {
echo "⚠️ Could not set ownership - you may need to run with appropriate permissions"
}
fi
fi
echo "✅ Cursor IDE support configured"
echo "🎯 Cursor will use optimized settings for this development environment"