nvim/.githooks/pre-commit

20 lines
575 B
Bash
Executable file

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