1
0
Fork 0
mirror of https://github.com/imjasonh/cnotes synced 2026-07-13 11:19:43 +00:00

Only register PostToolUse hook during installation

Since cnotes only handles PostToolUse events (and ignores all others),
update the installation to only register for that specific event rather
than all available hook events. This reduces unnecessary hook calls.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jason Hall 2025-07-21 16:59:15 -04:00
parent caa1834d58
commit 01ba9278ba
Failed to extract signature
3 changed files with 29 additions and 105 deletions

View file

@ -26,7 +26,7 @@ Use --local for local directory settings (./.claude/settings.json).
This command will:
1. Find or create the appropriate settings.json file
2. Add cnotes to handle PostToolUse events for Bash commands
2. Add cnotes to handle PostToolUse events for Bash commands containing git commits
3. Configure git to preserve notes during rebases
Use --uninstall to remove cnotes from Claude settings.`,
@ -70,28 +70,28 @@ func runInstall(cmd *cobra.Command, args []string) error {
// Prevent installation from temporary directories (unless uninstalling)
if !uninstall {
tempDir := os.TempDir()
// Resolve any symlinks in the executable path for comparison
realExecutable, err := filepath.EvalSymlinks(executable)
if err != nil {
realExecutable = executable // Fall back to original if can't resolve
}
// Also resolve tempDir in case it's a symlink (like /tmp on macOS)
realTempDir, err := filepath.EvalSymlinks(tempDir)
if err != nil {
realTempDir = tempDir
}
// Check if executable is in temp directory or is from go run
if strings.HasPrefix(realExecutable, tempDir) ||
strings.HasPrefix(executable, tempDir) ||
strings.HasPrefix(realExecutable, realTempDir) ||
strings.HasPrefix(executable, realTempDir) ||
strings.Contains(executable, "/go-build/") ||
strings.Contains(realExecutable, "/go-build/") ||
strings.Contains(executable, "/Caches/go-build/") ||
strings.Contains(realExecutable, "/Caches/go-build/") {
if strings.HasPrefix(realExecutable, tempDir) ||
strings.HasPrefix(executable, tempDir) ||
strings.HasPrefix(realExecutable, realTempDir) ||
strings.HasPrefix(executable, realTempDir) ||
strings.Contains(executable, "/go-build/") ||
strings.Contains(realExecutable, "/go-build/") ||
strings.Contains(executable, "/Caches/go-build/") ||
strings.Contains(realExecutable, "/Caches/go-build/") {
return fmt.Errorf("cannot install from temporary directory: %s\nPlease build and install cnotes properly:\n go install && cnotes install", executable)
}
}