diff --git a/scripts/copilot-update.fish b/scripts/copilot-update.fish index db63a31..fee6a6b 100644 --- a/scripts/copilot-update.fish +++ b/scripts/copilot-update.fish @@ -11,44 +11,142 @@ # fish ~/.local/bin/copilot-update.fish # git copilot-update (via Alias, ruft copilot-update.sh auf) -set SETUP_REPO_SSH "ssh://git@192.168.178.6:2222/cschulz/rd13_copilot_setup.git" -set SETUP_REPO_HTTP "http://192.168.178.6:8083/cschulz/rd13_copilot_setup.git" +# ── Konfiguration laden: env > config-file > leer ───────────────────────── +# Env-Variablen (Vorrang): +# COPILOT_SETUP_REMOTE_SSH / _HTTP Remote-URLs des Setup-Repos +# COPILOT_SETUP_DIR lokaler Klon/Arbeitskopie (Offline) +# COPILOT_SETUP_CONFIG alternativer Pfad zur Config-Datei +# Config-Datei (sh-Syntax KEY="value", wird geparst): $XDG_CONFIG_HOME/copilot-setup/config +# Standalone-Skript -> keine gemeinsame Lib sourcebar; gleiche Aufloesung in deploy.fish. -if set -q COPILOT_SETUP_DIR +# Wert fuer KEY aus sh-style Config lesen (KEY="value" | KEY=value); letzte Definition gewinnt +function _cfg_get --argument-names file key + test -f "$file"; or return 1 + set -l line (grep -E "^[[:space:]]*$key=" "$file" 2>/dev/null | tail -n1) + test -n "$line"; or return 1 + set -l val (string replace -r "^[[:space:]]*$key=" '' -- $line) + set val (string trim -- $val) + set val (string trim --chars '"' -- $val) + set val (string trim --chars "'" -- $val) + printf '%s' $val +end + +# VS Code User-Verzeichnis portabel ueber Editionen/OS ermitteln (identisch zu deploy.fish) +function detect_vscode_user_dir + for d in \ + "$HOME/.vscode-server/data/User" \ + "$HOME/.vscode-server-insiders/data/User" \ + "$HOME/Library/Application Support/Code/User" \ + "$HOME/Library/Application Support/Code - Insiders/User" \ + "$HOME/Library/Application Support/VSCodium/User" \ + "$HOME/Library/Application Support/Cursor/User" \ + "$HOME/.config/Code/User" \ + "$HOME/.config/Code - Insiders/User" \ + "$HOME/.config/VSCodium/User" \ + "$HOME/.config/Cursor/User" \ + "$HOME/.var/app/com.visualstudio.code/config/Code/User" \ + "/mnt/c/Users/$USER/AppData/Roaming/Code/User" \ + "/mnt/c/Users/$USER/AppData/Roaming/Code - Insiders/User" + if test -d "$d" + echo $d + return 0 + end + end + switch (uname -s) + case Darwin + echo "$HOME/Library/Application Support/Code/User" + case '*' + echo "$HOME/.config/Code/User" + end +end + +# Config-Datei-Pfad bestimmen +if set -q COPILOT_SETUP_CONFIG + set CONFIG_FILE $COPILOT_SETUP_CONFIG +else if set -q XDG_CONFIG_HOME + set CONFIG_FILE $XDG_CONFIG_HOME/copilot-setup/config +else + set CONFIG_FILE $HOME/.config/copilot-setup/config +end + +# Remote/Cache aufloesen: env hat Vorrang, sonst Config, sonst Default +if set -q COPILOT_SETUP_REMOTE_SSH; and test -n "$COPILOT_SETUP_REMOTE_SSH" + set SETUP_REPO_SSH $COPILOT_SETUP_REMOTE_SSH +else + set SETUP_REPO_SSH (_cfg_get $CONFIG_FILE COPILOT_SETUP_REMOTE_SSH) +end + +if set -q COPILOT_SETUP_REMOTE_HTTP; and test -n "$COPILOT_SETUP_REMOTE_HTTP" + set SETUP_REPO_HTTP $COPILOT_SETUP_REMOTE_HTTP +else + set SETUP_REPO_HTTP (_cfg_get $CONFIG_FILE COPILOT_SETUP_REMOTE_HTTP) +end + +if set -q COPILOT_SETUP_DIR; and test -n "$COPILOT_SETUP_DIR" set CACHE_DIR $COPILOT_SETUP_DIR else - set CACHE_DIR $HOME/.copilot-setup + set CACHE_DIR (_cfg_get $CONFIG_FILE COPILOT_SETUP_DIR) + test -n "$CACHE_DIR"; or set CACHE_DIR $HOME/.copilot-setup end echo "=== Copilot Update ===" # ── 1. Setup-Repo Cache aktuell halten ─────────────────────────────────────── +set HAVE_REMOTE 0 +if test -n "$SETUP_REPO_SSH"; or test -n "$SETUP_REPO_HTTP" + set HAVE_REMOTE 1 +end + +set SOURCE_OK 0 if test -d $CACHE_DIR/.git - echo " → Pulling latest from setup repo..." - if git -C $CACHE_DIR pull --ff-only --quiet 2>/dev/null - echo " ✓ Cache aktualisiert: $CACHE_DIR" + if test $HAVE_REMOTE -eq 1 + echo " → Pulling latest from setup repo..." + if git -C $CACHE_DIR pull --ff-only --quiet 2>/dev/null + echo " ✓ Cache aktualisiert: $CACHE_DIR" + else + echo " ⚠ git pull fehlgeschlagen – nutze vorhandenen Cache (offline)" + end else - echo " ✗ git pull fehlgeschlagen – versuche neu zu klonen..." - rm -rf $CACHE_DIR + echo " ─ Kein Remote konfiguriert – nutze lokalen Klon: $CACHE_DIR" + end + set SOURCE_OK 1 +else if test -d $CACHE_DIR/git-templates + echo " ─ Lokale Setup-Quelle ohne .git (Offline-Betrieb): $CACHE_DIR" + set SOURCE_OK 1 +else + if test -n "$SETUP_REPO_SSH" + echo " → Klone Setup-Repo (SSH)..." + if git clone --quiet $SETUP_REPO_SSH $CACHE_DIR 2>/dev/null + echo " ✓ Geklont via SSH" + set SOURCE_OK 1 + else + echo " ✗ SSH fehlgeschlagen" + end + end + if test $SOURCE_OK -eq 0; and test -n "$SETUP_REPO_HTTP" + echo " → Klone Setup-Repo (HTTP)..." + if git clone --quiet $SETUP_REPO_HTTP $CACHE_DIR 2>/dev/null + echo " ✓ Geklont via HTTP" + set SOURCE_OK 1 + else + echo " ✗ HTTP fehlgeschlagen" + end end end -if not test -d $CACHE_DIR/.git - echo " → Klone Setup-Repo (SSH)..." - if git clone --quiet $SETUP_REPO_SSH $CACHE_DIR 2>/dev/null - echo " ✓ Geklont via SSH" +if test $SOURCE_OK -eq 0 + echo "" + echo " ⚠ Keine Setup-Quelle verfuegbar – Update uebersprungen." + if test $HAVE_REMOTE -eq 1 + echo " Remote nicht erreichbar:" + test -n "$SETUP_REPO_SSH"; and echo " SSH: $SETUP_REPO_SSH" + test -n "$SETUP_REPO_HTTP"; and echo " HTTP: $SETUP_REPO_HTTP" else - echo " ✗ SSH fehlgeschlagen – versuche HTTP-Fallback..." - if git clone --quiet $SETUP_REPO_HTTP $CACHE_DIR 2>/dev/null - echo " ✓ Geklont via HTTP" - else - echo "" - echo " ✗ FEHLER: Setup-Repo nicht erreichbar." - echo " SSH: $SETUP_REPO_SSH" - echo " HTTP: $SETUP_REPO_HTTP" - exit 1 - end + echo " Kein Remote konfiguriert. Setze COPILOT_SETUP_REMOTE_SSH/_HTTP," + echo " COPILOT_SETUP_DIR (lokaler Klon) oder lege $CONFIG_FILE an." end + echo " (Kein Fehler – ohne Quelle gibt es nichts zu aktualisieren.)" + exit 0 end set SOURCE $CACHE_DIR @@ -87,15 +185,9 @@ cp $SOURCE/git-templates/history/summary/PROJECT_CONTEXT.md $GIT_TEMPLATE_DIR/hi echo " ✓ ~/.git-templates/ aktualisiert" # ── 3. VS Code Prompt-Dateien aktualisieren ─────────────────────────────────── -if test -d $HOME/.vscode-server/data/User - set VSCODE_USER $HOME/.vscode-server/data/User -else if test -d "$HOME/Library/Application Support/Code/User" - set VSCODE_USER "$HOME/Library/Application Support/Code/User" -else - set VSCODE_USER $HOME/.config/Code/User -end +set VSCODE_USER (detect_vscode_user_dir) -if test -d $VSCODE_USER +if test -d "$VSCODE_USER" mkdir -p $VSCODE_USER/prompts set PROMPTS_UPDATED 0 for f in $SOURCE/prompts/*.prompt.md diff --git a/scripts/copilot-update.sh b/scripts/copilot-update.sh index 35ce039..72f2824 100644 --- a/scripts/copilot-update.sh +++ b/scripts/copilot-update.sh @@ -11,38 +11,113 @@ # copilot-update.sh # aktuelles Verzeichnis (Git-Repo optional) # git copilot-update # via Git-Alias -SETUP_REPO_SSH="ssh://git@192.168.178.6:2222/cschulz/rd13_copilot_setup.git" -SETUP_REPO_HTTP="http://192.168.178.6:8083/cschulz/rd13_copilot_setup.git" +# ── Konfiguration laden: env > config-file > leer ───────────────────────── +# Env-Variablen (Vorrang): +# COPILOT_SETUP_REMOTE_SSH / _HTTP Remote-URLs des Setup-Repos +# COPILOT_SETUP_DIR lokaler Klon/Arbeitskopie (Offline) +# COPILOT_SETUP_CONFIG alternativer Pfad zur Config-Datei +# Config-Datei (sh-Syntax, gesourct): $XDG_CONFIG_HOME/copilot-setup/config +# Standalone-Skript -> keine gemeinsame Lib sourcebar; gleiche Aufloesung in +# deploy.sh. Bei Aenderungen beide Stellen pflegen. +_env_ssh="${COPILOT_SETUP_REMOTE_SSH:-}" +_env_http="${COPILOT_SETUP_REMOTE_HTTP:-}" +_env_dir="${COPILOT_SETUP_DIR:-}" + +CONFIG_FILE="${COPILOT_SETUP_CONFIG:-${XDG_CONFIG_HOME:-$HOME/.config}/copilot-setup/config}" +if [ -f "$CONFIG_FILE" ]; then + . "$CONFIG_FILE" +fi + +# Env ueberschreibt Werte aus der Config-Datei +[ -n "$_env_ssh" ] && COPILOT_SETUP_REMOTE_SSH="$_env_ssh" +[ -n "$_env_http" ] && COPILOT_SETUP_REMOTE_HTTP="$_env_http" +[ -n "$_env_dir" ] && COPILOT_SETUP_DIR="$_env_dir" + +SETUP_REPO_SSH="${COPILOT_SETUP_REMOTE_SSH:-}" +SETUP_REPO_HTTP="${COPILOT_SETUP_REMOTE_HTTP:-}" CACHE_DIR="${COPILOT_SETUP_DIR:-$HOME/.copilot-setup}" +have_remote() { [ -n "$SETUP_REPO_SSH" ] || [ -n "$SETUP_REPO_HTTP" ]; } + +clone_setup_repo() { + if [ -n "$SETUP_REPO_SSH" ]; then + echo " → Klone Setup-Repo (SSH)..." + if git clone --quiet "$SETUP_REPO_SSH" "$CACHE_DIR" 2>/dev/null; then + echo " ✓ Geklont via SSH"; return 0 + fi + echo " ✗ SSH fehlgeschlagen" + fi + if [ -n "$SETUP_REPO_HTTP" ]; then + echo " → Klone Setup-Repo (HTTP)..." + if git clone --quiet "$SETUP_REPO_HTTP" "$CACHE_DIR" 2>/dev/null; then + echo " ✓ Geklont via HTTP"; return 0 + fi + echo " ✗ HTTP fehlgeschlagen" + fi + return 1 +} + +# VS Code User-Verzeichnis portabel ueber Editionen/OS ermitteln. +# Identischer Block in deploy.sh (Standalone -> keine Lib sourcebar). +detect_vscode_user_dir() { + for d in \ + "$HOME/.vscode-server/data/User" \ + "$HOME/.vscode-server-insiders/data/User" \ + "$HOME/Library/Application Support/Code/User" \ + "$HOME/Library/Application Support/Code - Insiders/User" \ + "$HOME/Library/Application Support/VSCodium/User" \ + "$HOME/Library/Application Support/Cursor/User" \ + "$HOME/.config/Code/User" \ + "$HOME/.config/Code - Insiders/User" \ + "$HOME/.config/VSCodium/User" \ + "$HOME/.config/Cursor/User" \ + "$HOME/.var/app/com.visualstudio.code/config/Code/User" \ + "/mnt/c/Users/$USER/AppData/Roaming/Code/User" \ + "/mnt/c/Users/$USER/AppData/Roaming/Code - Insiders/User" + do + if [ -d "$d" ]; then + printf '%s\n' "$d" + return 0 + fi + done + case "$(uname -s)" in + Darwin) printf '%s\n' "$HOME/Library/Application Support/Code/User" ;; + *) printf '%s\n' "$HOME/.config/Code/User" ;; + esac +} + echo "=== Copilot Update ===" # ── 1. Setup-Repo Cache aktuell halten ─────────────────────────────────────── if [ -d "$CACHE_DIR/.git" ]; then - echo " → Pulling latest from setup repo..." - if git -C "$CACHE_DIR" pull --ff-only --quiet 2>/dev/null; then - echo " ✓ Cache aktualisiert: $CACHE_DIR" - else - echo " ✗ git pull fehlgeschlagen – versuche neu zu klonen..." - rm -rf "$CACHE_DIR" - fi -fi - -if [ ! -d "$CACHE_DIR/.git" ]; then - echo " → Klone Setup-Repo (SSH)..." - if git clone --quiet "$SETUP_REPO_SSH" "$CACHE_DIR" 2>/dev/null; then - echo " ✓ Geklont via SSH" - else - echo " ✗ SSH fehlgeschlagen – versuche HTTP-Fallback..." - if git clone --quiet "$SETUP_REPO_HTTP" "$CACHE_DIR" 2>/dev/null; then - echo " ✓ Geklont via HTTP" + if have_remote; then + echo " → Pulling latest from setup repo..." + if git -C "$CACHE_DIR" pull --ff-only --quiet 2>/dev/null; then + echo " ✓ Cache aktualisiert: $CACHE_DIR" else - echo "" - echo " ✗ FEHLER: Setup-Repo nicht erreichbar." - echo " SSH: $SETUP_REPO_SSH" - echo " HTTP: $SETUP_REPO_HTTP" - exit 1 + echo " ⚠ git pull fehlgeschlagen – nutze vorhandenen Cache (offline)" fi + else + echo " ─ Kein Remote konfiguriert – nutze lokalen Klon: $CACHE_DIR" + fi +elif [ -d "$CACHE_DIR/git-templates" ]; then + echo " ─ Lokale Setup-Quelle ohne .git (Offline-Betrieb): $CACHE_DIR" +else + if have_remote && clone_setup_repo; then + : + else + echo "" + echo " ⚠ Keine Setup-Quelle verfuegbar – Update uebersprungen." + if have_remote; then + echo " Remote nicht erreichbar:" + [ -n "$SETUP_REPO_SSH" ] && echo " SSH: $SETUP_REPO_SSH" + [ -n "$SETUP_REPO_HTTP" ] && echo " HTTP: $SETUP_REPO_HTTP" + else + echo " Kein Remote konfiguriert. Setze COPILOT_SETUP_REMOTE_SSH/_HTTP," + echo " COPILOT_SETUP_DIR (lokaler Klon) oder lege $CONFIG_FILE an." + fi + echo " (Kein Fehler – ohne Quelle gibt es nichts zu aktualisieren.)" + exit 0 fi fi @@ -83,13 +158,7 @@ cp "$SOURCE/git-templates/history/summary/PROJECT_CONTEXT.md" "$GIT_TEMPLATE_DIR echo " ✓ ~/.git-templates/ aktualisiert" # ── 3. VS Code Prompt-Dateien aktualisieren ─────────────────────────────────── -if [ -d "$HOME/.vscode-server/data/User" ]; then - VSCODE_USER="$HOME/.vscode-server/data/User" -elif [ -d "$HOME/Library/Application Support/Code/User" ]; then - VSCODE_USER="$HOME/Library/Application Support/Code/User" -else - VSCODE_USER="$HOME/.config/Code/User" -fi +VSCODE_USER="$(detect_vscode_user_dir)" if [ -d "$VSCODE_USER" ]; then mkdir -p "$VSCODE_USER/prompts"