run-hook.cmd 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. : << 'CMDBLOCK'
  2. @echo off
  3. REM Cross-platform wrapper for this plugin's hook scripts (same approach as the superpowers plugin).
  4. REM On Windows cmd.exe runs this batch part, which finds Git Bash and runs the named script with it.
  5. REM On macOS and Linux the shell reads ":" as a no-op, skips the heredoc, and runs the script with sh.
  6. REM The scripts are POSIX sh, so the hooks need no Node installation.
  7. REM
  8. REM Usage: run-hook.cmd <script-name> [args...]
  9. if "%~1"=="" exit /b 0
  10. set "HOOK_DIR=%~dp0"
  11. if exist "%ProgramFiles%\Git\bin\bash.exe" (
  12. "%ProgramFiles%\Git\bin\bash.exe" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
  13. exit /b 0
  14. )
  15. if exist "%ProgramFiles(x86)%\Git\bin\bash.exe" (
  16. "%ProgramFiles(x86)%\Git\bin\bash.exe" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
  17. exit /b 0
  18. )
  19. if exist "%LOCALAPPDATA%\Programs\Git\bin\bash.exe" (
  20. "%LOCALAPPDATA%\Programs\Git\bin\bash.exe" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
  21. exit /b 0
  22. )
  23. where bash >nul 2>nul
  24. if %ERRORLEVEL% equ 0 (
  25. bash "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
  26. exit /b 0
  27. )
  28. REM No bash: exit quietly, so the session and tool calls are never blocked.
  29. exit /b 0
  30. CMDBLOCK
  31. script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) || exit 0
  32. script_name=$1
  33. [ -n "$script_name" ] || exit 0
  34. shift
  35. exec sh "$script_dir/$script_name" "$@"