Files
Rules/init-cursor.sh
T
PapaTramp bdf405e2c1 Добавить bootstrap для новых ПК и Linux-скрипты.
SSH-ключи и Gitea API до clone Rules; init-cursor копирует из локального $HOME/CursorRules.
2026-06-18 10:01:11 +10:00

86 lines
2.6 KiB
Bash

#!/usr/bin/env bash
# Копирует Cursor rules из локального $HOME/CursorRules в текущий проект.
init-cursor() {
local source="$HOME/CursorRules"
local rules_src="$source/.cursor/rules"
local scripts="$source/scripts"
local update=0
local skip_git_remotes=0
while [[ $# -gt 0 ]]; do
case "$1" in
-Update|--update) update=1; shift ;;
-SkipGitRemotes|--skip-git-remotes) skip_git_remotes=1; shift ;;
*) shift ;;
esac
done
if [[ ! -d "$source" ]]; then
echo "Error: $source not found — run bootstrap.sh on this machine first" >&2
return 1
fi
if [[ "$update" == '1' && -d "$source/.git" ]]; then
echo '[*] Updating CursorRules from remote...'
if git -C "$source" pull --ff-only; then
echo '[+] CursorRules updated'
else
echo '[!] git pull failed in CursorRules' >&2
fi
fi
if [[ -f "$source/.cursorignore" ]]; then
cp -f "$source/.cursorignore" .
echo '[+] .cursorignore copied'
fi
if [[ -d "$rules_src" ]]; then
mkdir -p ./.cursor/rules
cp -f "$rules_src"/*.mdc ./.cursor/rules/
echo '[+] .cursor/rules (*.mdc) copied'
fi
if [[ -d .git ]]; then
local gitignore='.gitignore'
for line in '.cursor/' '.cursorignore'; do
if [[ ! -f "$gitignore" ]]; then
printf '%s\n' "$line" > "$gitignore"
echo "[+] .gitignore created ($line)"
elif ! grep -Fxq "$line" "$gitignore" 2>/dev/null; then
printf '%s\n' "$line" >> "$gitignore"
echo "[+] .gitignore updated ($line)"
fi
done
fi
if [[ "$skip_git_remotes" == '1' ]]; then
echo '[!] Git remotes skipped'
return 0
fi
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo '[!] Not a git repo — remotes skipped'
return 0
fi
if [[ -f "$scripts/Set-GitRemotes.sh" ]]; then
echo '[*] Configuring git remotes...'
bash "$scripts/Set-GitRemotes.sh" || true
elif [[ -f "$scripts/Set-GitRemotes.ps1" ]]; then
echo '[!] Set-GitRemotes.ps1 only; install bash script or pwsh' >&2
fi
if [[ -f "$scripts/Ensure-GiteaHomeRepo.ps1" ]]; then
local repo_name
repo_name="$(basename "$(git rev-parse --show-toplevel)")"
echo "[*] Ensuring home Gitea repo: $repo_name"
if command -v pwsh >/dev/null 2>&1; then
pwsh -NoProfile -File "$scripts/Ensure-GiteaHomeRepo.ps1" -RepoName "$repo_name" || true
elif command -v powershell >/dev/null 2>&1; then
powershell -NoProfile -ExecutionPolicy Bypass -File "$scripts/Ensure-GiteaHomeRepo.ps1" -RepoName "$repo_name" || true
else
echo '[!] PowerShell not found — skip Ensure-GiteaHomeRepo.ps1' >&2
fi
fi
}