pre-commit 575 B

1234567891011121314151617181920
  1. #!/usr/bin/env bash
  2. # Git pre-commit hook to format Lua files with stylua
  3. # Check if stylua is available in PATH
  4. if ! command -v stylua &>/dev/null; then
  5. echo "Error: stylua not found. Please install it via NixOS configuration."
  6. exit 1
  7. fi
  8. # Get staged Lua files
  9. LUA_FILES=$(git diff --cached --name-only --diff-filter=AM | grep '\.lua$')
  10. if [ -n "$LUA_FILES" ]; then
  11. echo "Formatting Lua files with stylua..."
  12. echo "$LUA_FILES" | xargs stylua
  13. echo "$LUA_FILES" | xargs git add
  14. echo "Lua files formatted and re-staged."
  15. else
  16. echo "No Lua files to format."
  17. fi