exbrain/vault-template/scripts/on-file-change.sh
Masahiro Chaen 2c2343e081 fix: resolve all errors from full repository audit
- README/README_JP: fix X bookmark schedule "22:00" → "every 4 hours"
- README: standardize skill name /auto-min → /auto-mins
- sync-x-bookmarks.sh: fix subshell variable scope (NEW_COUNT always 0)
  Use process substitution instead of pipe to preserve counter
- CLAUDE.md: add missing frontmatter (violated own schema rules)
- clips/_index.md: replace personal test data with clean template
- on-file-change.sh: replace bare except with specific exceptions
- on-session-end.sh: use context managers for file handles

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 23:29:08 +09:00

48 lines
1.3 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# on-file-change.sh — Claude Code PostToolUse hook (Write|Edit)
# ファイル変更時にvaultの関連ページを更新する
# 呼び出し元: ~/.claude/settings.json → hooks.PostToolUse (async: true)
set +e
LOG="$HOME/vault/.sync.log"
# stdinからJSONtool_inputを読み取る
INPUT=$(cat 2>/dev/null || true)
[ -z "$INPUT" ] && exit 0
# 変更されたファイルパスを抽出
FP=$(echo "$INPUT" | python3 -c "
import sys, json
try:
d = json.load(sys.stdin)
ti = d.get('tool_input', d)
print(ti.get('file_path', ti.get('path', '')))
except (json.JSONDecodeError, AttributeError, TypeError, KeyError):
print('')
" 2>/dev/null || echo "")
[ -z "$FP" ] && exit 0
# パスに基づいて同期対象を判定case文でgrepを避ける
case "$FP" in
*/vault/*)
# vault内のファイル変更は無視再帰防止
;;
*/CLAUDE.md)
echo "[$(date '+%F %T')] CLAUDE.md changed: $FP" >> "$LOG"
;;
*/.claude/projects/*/memory/*|*/memory/*)
echo "[$(date '+%F %T')] Memory changed: $FP" >> "$LOG"
;;
*/.claude/skills/*|*/skills/*)
echo "[$(date '+%F %T')] Skill changed: $FP" >> "$LOG"
;;
*/clients/*/minutes/*)
echo "[$(date '+%F %T')] Minutes changed: $FP" >> "$LOG"
;;
*)
# 同期対象外
;;
esac
exit 0