diegobeyl/backtesting
2
1#!/usr/bin/env python32"""3Script para arreglar VS Code Shell Integration en macOS M2 con zsh4"""5 6import os7import subprocess8import sys9 10def run_command(cmd):11 """Ejecutar comando y retornar resultado"""12 try:13 result = subprocess.run(cmd, shell=True, capture_output=True, text=True)14 return result.stdout.strip(), result.stderr.strip(), result.returncode15 except Exception as e:16 return "", str(e), 117 18def main():19 home = os.path.expanduser("~")20 zshrc_path = os.path.join(home, ".zshrc")21 22 print("=" * 60)23 print("🔧 ARREGLANDO VS CODE SHELL INTEGRATION")24 print("=" * 60)25 26 # 1. Verificar que code está en PATH27 print("\n1️⃣ Verificando comando 'code'...")28 code_path, _, code_rc = run_command("which code")29 if code_rc != 0:30 print(" ⚠️ 'code' no está en PATH. Instalando...")31 os.system('sudo ln -sf "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/code 2>/dev/null')32 code_path, _, _ = run_command("which code")33 print(f" ✅ code: {code_path}")34 35 # 2. Obtener ruta de integración36 print("\n2️⃣ Obteniendo ruta de integración...")37 integration_path, _, rc = run_command("code --locate-shell-integration-path zsh")38 if rc == 0:39 print(f" ✅ Ruta: {integration_path}")40 else:41 print(f" ❌ Error obteniendo ruta: {integration_path}")42 return 143 44 # 3. Configurar .zshrc45 print("\n3️⃣ Configurando ~/.zshrc...")46 47 # Leer el contenido actual48 try:49 with open(zshrc_path, 'r') as f:50 content = f.read()51 except FileNotFoundError:52 content = ""53 54 # Verificar si ya está configurado55 if "VS Code Terminal Shell Integration" in content:56 print(" ✅ Ya está configurado")57 else:58 # Añadir configuración59 new_config = f'''60# ============================================61# VS Code Terminal Shell Integration62# ============================================63if [[ "$TERM_PROGRAM" == "vscode" ]]; then64 source "{integration_path}" 2>/dev/null || true65fi66'''67 with open(zshrc_path, 'a') as f:68 f.write(new_config)69 print(" ✅ Configuración añadida")70 71 # 4. Verificar .vscode/settings.json72 print("\n4️⃣ Verificando VS Code settings...")73 vscode_dir = "/Users/javier/Projects/backtesting_app_v2/.vscode"74 settings_file = os.path.join(vscode_dir, "settings.json")75 76 if os.path.exists(settings_file):77 print(" ✅ settings.json existe")78 else:79 os.makedirs(vscode_dir, exist_ok=True)80 settings = """{81 "terminal.integrated.shellIntegration.enabled": true,82 "terminal.integrated.defaultProfile.osx": "zsh",83 "terminal.integrated.profiles.osx": {84 "zsh": {85 "path": "/bin/zsh",86 "args": ["-l"]87 }88 }89}90"""91 with open(settings_file, 'w') as f:92 f.write(settings)93 print(" ✅ settings.json creado")94 95 print("\n" + "=" * 60)96 print("✅ CONFIGURACIÓN COMPLETADA")97 print("=" * 60)98 print("\n📝 PRÓXIMOS PASOS:")99 print("1. Cierra VS Code (Cmd + Q)")100 print("2. Abre VS Code nuevamente")101 print("3. Abre un NUEVO terminal (Ctrl + `)")102 print("4. Ejecuta: echo $VSCODE_SHELL_INTEGRATION")103 print(" Debe devolver: 1")104 print("\n")105 106if __name__ == "__main__":107 sys.exit(main())108 