Files
Rules/init-cursor.ps1
T
PapaTramp 3adf0c5211 Добавить Cursor rules, init-cursor и скрипты настройки git remotes.
Канонический источник для клонирования в $HOME\CursorRules на новых ПК.
2026-06-18 09:51:39 +10:00

93 lines
3.1 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#Requires -Version 5.1
<#
.SYNOPSIS
Копирует Cursor rules в текущий каталог и настраивает git remotes.
.DESCRIPTION
1. .cursorignore из $HOME\CursorRules
2. .cursor/rules/*.mdc
3. В git-репо: Set-GitRemotes.ps1 + Ensure-GiteaHomeRepo.ps1 (home Gitea)
.EXAMPLE
cd C:\Users\papat\Projects\MyRepo
init-cursor
#>
function init-cursor {
[CmdletBinding()]
param(
[switch]$SkipGitRemotes
)
$source = Join-Path $HOME 'CursorRules'
$rulesSrc = Join-Path $source '.cursor\rules'
$scripts = Join-Path $source 'scripts'
if (-not (Test-Path $source)) {
Write-Host "Error: $source not found" -ForegroundColor Red
return
}
$cursorIgnore = Join-Path $source '.cursorignore'
if (Test-Path $cursorIgnore) {
Copy-Item $cursorIgnore . -Force
Write-Host '[+] .cursorignore copied' -ForegroundColor Green
}
if (Test-Path $rulesSrc) {
New-Item -ItemType Directory -Path '.\.cursor\rules' -Force | Out-Null
Copy-Item (Join-Path $rulesSrc '*.mdc') '.\.cursor\rules\' -Force
Write-Host '[+] .cursor/rules (*.mdc) copied' -ForegroundColor Green
}
$gitIgnorePath = Join-Path (Get-Location) '.gitignore'
$ignoreLines = @('.cursor/', '.cursorignore')
if (Test-Path (Join-Path (Get-Location) '.git')) {
if (-not (Test-Path $gitIgnorePath)) {
Set-Content -Path $gitIgnorePath -Value ($ignoreLines -join "`n") -Encoding UTF8
Write-Host '[+] .gitignore created (.cursor/, .cursorignore)' -ForegroundColor Green
}
else {
$existing = Get-Content $gitIgnorePath -Raw
$added = @()
foreach ($line in $ignoreLines) {
if ($existing -notmatch "(?m)^$([regex]::Escape($line))\s*$") {
Add-Content -Path $gitIgnorePath -Value $line
$added += $line
}
}
if ($added.Count -gt 0) {
Write-Host "[+] .gitignore updated: $($added -join ', ')" -ForegroundColor Green
}
}
}
if ($SkipGitRemotes) {
Write-Host '[!] Git remotes skipped (-SkipGitRemotes)' -ForegroundColor Yellow
return
}
git rev-parse --is-inside-work-tree 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host '[!] Not a git repo — remotes skipped' -ForegroundColor Yellow
return
}
$setRemotes = Join-Path $scripts 'Set-GitRemotes.ps1'
if (Test-Path $setRemotes) {
Write-Host '[*] Configuring git remotes...' -ForegroundColor Cyan
& powershell -NoProfile -ExecutionPolicy Bypass -File $setRemotes
}
$ensureRepo = Join-Path $scripts 'Ensure-GiteaHomeRepo.ps1'
if (Test-Path $ensureRepo) {
$repoName = Split-Path -Leaf (git rev-parse --show-toplevel)
Write-Host "[*] Ensuring home Gitea repo: $repoName" -ForegroundColor Cyan
try {
& powershell -NoProfile -ExecutionPolicy Bypass -File $ensureRepo -RepoName $repoName
}
catch {
Write-Host "[!] home Gitea ensure failed: $($_.Exception.Message)" -ForegroundColor Yellow
}
}
}