136 lines
3.2 KiB
Batchfile
136 lines
3.2 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
rem Install Codex skills from this Playbook snapshot into CODEX_HOME.
|
|
rem - Source: <snapshot>\codex\skills\<skill-name>\
|
|
rem - Dest: %CODEX_HOME%\skills\<skill-name>\ (default CODEX_HOME=%USERPROFILE%\.codex)
|
|
rem
|
|
rem Usage:
|
|
rem install_codex_skills.bat -all
|
|
rem install_codex_skills.bat -skills style-cleanup,commit-message
|
|
rem install_codex_skills.bat -local -all
|
|
rem
|
|
rem Notes:
|
|
rem - Codex loads skills at startup; restart `codex` after installation.
|
|
rem - Existing destination skill dirs are backed up with a random suffix.
|
|
|
|
set "SCRIPT_DIR=%~dp0"
|
|
for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI"
|
|
set "SKILLS_SRC_ROOT=%SRC%\\codex\\skills"
|
|
|
|
set "LOCAL_MODE=0"
|
|
set "INSTALL_ALL=0"
|
|
set "SKILLS="
|
|
:parse_opts
|
|
if "%~1"=="" goto opts_done
|
|
if /I "%~1"=="-help" goto show_help
|
|
if /I "%~1"=="-h" goto show_help
|
|
if /I "%~1"=="-local" (
|
|
set "LOCAL_MODE=1"
|
|
shift
|
|
goto parse_opts
|
|
)
|
|
if /I "%~1"=="-l" (
|
|
set "LOCAL_MODE=1"
|
|
shift
|
|
goto parse_opts
|
|
)
|
|
if /I "%~1"=="-all" (
|
|
set "INSTALL_ALL=1"
|
|
shift
|
|
goto parse_opts
|
|
)
|
|
if /I "%~1"=="-skills" (
|
|
if "%~2"=="" (
|
|
echo ERROR: -skills requires a value.
|
|
exit /b 1
|
|
)
|
|
set "SKILLS=%~2"
|
|
shift
|
|
shift
|
|
goto parse_opts
|
|
)
|
|
echo ERROR: Unknown option: %~1
|
|
exit /b 1
|
|
goto opts_done
|
|
|
|
:opts_done
|
|
set "CODEX_HOME=%CODEX_HOME%"
|
|
if "%LOCAL_MODE%"=="1" if "%CODEX_HOME%"=="" set "CODEX_HOME=%CD%\\.codex"
|
|
if "%CODEX_HOME%"=="" set "CODEX_HOME=%USERPROFILE%\\.codex"
|
|
set "SKILLS_DST_ROOT=%CODEX_HOME%\\skills"
|
|
|
|
if not exist "%SKILLS_SRC_ROOT%" (
|
|
echo ERROR: skills source dir not found: "%SKILLS_SRC_ROOT%"
|
|
exit /b 1
|
|
)
|
|
|
|
if not exist "%SKILLS_DST_ROOT%" mkdir "%SKILLS_DST_ROOT%"
|
|
|
|
if "%INSTALL_ALL%"=="1" if not "%SKILLS%"=="" (
|
|
echo ERROR: use either -all or -skills, not both.
|
|
exit /b 1
|
|
)
|
|
if "%INSTALL_ALL%"=="0" if "%SKILLS%"=="" (
|
|
echo ERROR: -all or -skills is required.
|
|
exit /b 1
|
|
)
|
|
|
|
if "%INSTALL_ALL%"=="1" (
|
|
for /d %%D in ("%SKILLS_SRC_ROOT%\\*") do (
|
|
set "NAME=%%~nD"
|
|
if not "!NAME!"=="" if not "!NAME:~0,1!"=="." call :InstallOne "!NAME!"
|
|
)
|
|
) else (
|
|
set "SKILLS=%SKILLS:,= %"
|
|
for %%S in (%SKILLS%) do call :InstallOne "%%~S"
|
|
)
|
|
|
|
:Done
|
|
echo Done. Skills installed to: "%SKILLS_DST_ROOT%"
|
|
endlocal
|
|
exit /b 0
|
|
|
|
:show_help
|
|
echo Usage:
|
|
echo install_codex_skills.bat -all
|
|
echo install_codex_skills.bat -skills style-cleanup,commit-message
|
|
echo.
|
|
echo Options:
|
|
echo -local, -l Install to .\\.codex ^(or CODEX_HOME if set^)
|
|
echo -skills LIST Comma/space-separated skill names
|
|
echo -all Install all skills
|
|
echo -help, -h Show this help
|
|
echo.
|
|
echo Env:
|
|
echo CODEX_HOME Target Codex home ^(default: %%USERPROFILE%%\\.codex^)
|
|
exit /b 0
|
|
|
|
:InstallOne
|
|
set "NAME=%~1"
|
|
set "SRC_DIR=%SKILLS_SRC_ROOT%\\%NAME%"
|
|
set "DST_DIR=%SKILLS_DST_ROOT%\\%NAME%"
|
|
|
|
if not exist "%SRC_DIR%" (
|
|
echo ERROR: skill not found: %NAME% "%SRC_DIR%"
|
|
exit /b 1
|
|
)
|
|
|
|
if exist "%DST_DIR%" (
|
|
set "RAND=%RANDOM%"
|
|
pushd "%SKILLS_DST_ROOT%"
|
|
ren "%NAME%" "%NAME%.bak.!RAND!"
|
|
popd
|
|
echo Backed up existing skill: %NAME% -> %NAME%.bak.!RAND!
|
|
)
|
|
|
|
xcopy "%SRC_DIR%\\*" "%DST_DIR%\\" /e /i /y >nul
|
|
if errorlevel 1 (
|
|
echo ERROR: failed to copy skill: %NAME%
|
|
exit /b 1
|
|
)
|
|
|
|
echo Installed: %NAME%
|
|
exit /b 0
|
|
|