From fd76361e2d3c8c6ff3187cf4eaf89a4f71309412 Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Thu, 30 Jul 2026 11:41:15 +0300 Subject: [PATCH] fix: respect HISTFILE env var for shell history path Check the HISTFILE environment variable to determine the history file location. Falls back to default paths (`.bash_history` or `.zsh_history`) based on the shell type if HISTFILE is not set. This enables XDG-compliant history configurations. Closes #1 --- cmd/index.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/index.go b/cmd/index.go index 8a265fb..8183e13 100644 --- a/cmd/index.go +++ b/cmd/index.go @@ -181,8 +181,7 @@ func watchIndex(ctx context.Context, cfg config.Config, store *storage.Store, in watchPaths = cfg.IndexedPaths } } - home := utils.MustHome() - watchPaths = append(watchPaths, filepath.Join(home, ".bash_history"), filepath.Join(home, ".zsh_history")) + watchPaths = append(watchPaths, historyPaths()...) added := map[string]struct{}{} for _, path := range watchPaths { expanded, err := utils.ExpandHome(path) @@ -363,8 +362,7 @@ func runDryRun(ctx context.Context, cfg config.Config, sources []string, paths [ } summary := dryRunSummary{} if sourceSet["history"] { - home := utils.MustHome() - for _, path := range []string{filepath.Join(home, ".bash_history"), filepath.Join(home, ".zsh_history")} { + for _, path := range historyPaths() { info, err := os.Stat(path) if err != nil || info.IsDir() { continue @@ -460,3 +458,17 @@ func countLines(path string) (int, error) { } return count, scanner.Err() } + +func historyPaths() []string { + histFile := os.Getenv("HISTFILE") + if histFile != "" { + if expanded, err := utils.ExpandHome(histFile); err == nil && expanded != "" { + return []string{expanded} + } + } + home := utils.MustHome() + return []string{ + filepath.Join(home, ".bash_history"), + filepath.Join(home, ".zsh_history"), + } +}