Files
dotfiles/.claude/hooks/post-edit-format.sh
Ismo Vuorinen cff83e4738 refactor(claude): migrate hooks to external scripts and add new hooks
Replace inline command strings in settings.json with external scripts
in .claude/hooks/ for readability and maintainability. Consolidate
three PostToolUse formatters into one script and add markdown/yaml
formatting. Add new hooks: SessionStart context banner, Stop lint
gate, async Bats test runner, idle desktop notification, and
PostToolUseFailure logger.
2026-03-20 04:38:18 +02:00

31 lines
833 B
Bash
Executable File

#!/usr/bin/env bash
# Post-edit formatter: auto-format file based on extension.
# Receives tool output JSON on stdin.
fp=$(jq -r '.tool_input.file_path // empty')
[ -z "$fp" ] || [ ! -f "$fp" ] && exit 0
case "$fp" in
*.sh | */bin/*)
head -1 "$fp" | grep -qE '^#!.*(ba)?sh' \
&& command -v shfmt > /dev/null \
&& shfmt -i 2 -bn -ci -sr -fn -w "$fp"
;;
*.fish)
command -v fish_indent > /dev/null && fish_indent -w "$fp"
;;
*.lua)
command -v stylua > /dev/null && stylua "$fp"
;;
*.md)
command -v biome > /dev/null && biome format --write "$fp" 2> /dev/null
command -v markdown-table-formatter > /dev/null \
&& markdown-table-formatter "$fp" 2> /dev/null
;;
*.yml | *.yaml)
command -v prettier > /dev/null && prettier --write "$fp" 2> /dev/null
;;
esac
exit 0