@@ -5,6 +5,7 @@ import (
6 "path/filepath"
6 "path/filepath"
9 "github.com/charlievieth/fastwalk"
10 "github.com/charlievieth/fastwalk"
10 "github.com/charmbracelet/crush/internal/config"
11 "github.com/charmbracelet/crush/internal/config"
@@ -13,62 +14,79 @@ import (
15// commonIgnorePatterns contains commonly ignored files and directories
16// commonIgnorePatterns contains commonly ignored files and directories
16−var commonIgnorePatterns = ignore.CompileIgnoreLines(
17+var commonIgnorePatterns = sync.OnceValue(func() ignore.IgnoreParser {
18+ return ignore.CompileIgnoreLines(
17− // Version control
19+ // Version control
23− // IDE and editor files
25+ // IDE and editor files
24− ".vscode",
26+ ".vscode",
29− ".DS_Store",
31+ ".DS_Store",
30− "Thumbs.db",
32+ "Thumbs.db",
32− // Build artifacts and dependencies
34+ // Build artifacts and dependencies
33− "node_modules",
35+ "node_modules",
34− "target",
36+ "target",
42− "*.dylib",
44+ "*.dylib",
46− // Logs and temporary files
48+ // Logs and temporary files
49− "*.temp",
51+ "*.temp",
50− ".cache",
52+ ".cache",
53− // Language-specific
55+ // Language-specific
54− "__pycache__",
56+ "__pycache__",
57− ".pytest_cache",
59+ ".pytest_cache",
58− "vendor",
60+ "vendor",
59− "Cargo.lock",
61+ "Cargo.lock",
60− "package-lock.json",
62+ "package-lock.json",
61− "yarn.lock",
63+ "yarn.lock",
62− "pnpm-lock.yaml",
64+ "pnpm-lock.yaml",
64− // OS generated files
66+ // OS generated files
65− ".Trash",
67+ ".Trash",
66− ".Spotlight-V100",
68+ ".Spotlight-V100",
67− ".fseventsd",
69+ ".fseventsd",
70− ".crush",
72+ ".crush",
76+var homeIgnore = sync.OnceValue(func() ignore.IgnoreParser {
77+ home := config.HomeDir()
79+ for _, name := range []string{
80+ filepath.Join(home, ".gitignore"),
81+ filepath.Join(home, ".config", "git", "ignore"),
82+ filepath.Join(home, ".config", "crush", "ignore"),
84+ if bts, err := os.ReadFile(name); err == nil {
85+ lines = append(lines, strings.Split(string(bts), "\n")...)
88+ return ignore.CompileIgnoreLines(lines...)
73type directoryLister struct {
91type directoryLister struct {
74 ignores *csync.Map[string, ignore.IgnoreParser]
92 ignores *csync.Map[string, ignore.IgnoreParser]
@@ -81,20 +99,6 @@ func NewDirectoryLister(rootPath string) *directoryLister {
81 ignores: csync.NewMap[string, ignore.IgnoreParser](),
99 ignores: csync.NewMap[string, ignore.IgnoreParser](),
83 dl.getIgnore(rootPath)
101 dl.getIgnore(rootPath)
84− dl.ignores.GetOrSet("~", func() ignore.IgnoreParser {
85− home := config.HomeDir()
87− for _, name := range []string{
88− filepath.Join(home, ".gitignore"),
89− filepath.Join(home, ".config", "git", "ignore"),
90− filepath.Join(home, ".config", "crush", "ignore"),
92− if bts, err := os.ReadFile(name); err == nil {
93− lines = append(lines, strings.Split(string(bts), "\n")...)
96− return ignore.CompileIgnoreLines(lines...)
98 return dl
102 return dl
@@ -126,7 +130,7 @@ func (dl *directoryLister) shouldIgnore(path string, ignorePatterns []string) bo
126 relPath = path
130 relPath = path
129− if commonIgnorePatterns.MatchesPath(relPath) {
133+ if commonIgnorePatterns().MatchesPath(relPath) {
130 slog.Debug("ingoring common pattern", "path", relPath)
134 slog.Debug("ingoring common pattern", "path", relPath)
131 return true
135 return true
@@ -140,7 +144,7 @@ func (dl *directoryLister) shouldIgnore(path string, ignorePatterns []string) bo
140 return true
144 return true
143− if dl.getIgnore("~").MatchesPath(relPath) {
147+ if homeIgnore().MatchesPath(relPath) {
144 slog.Debug("ingoring home dir pattern", "path", relPath)
148 slog.Debug("ingoring home dir pattern", "path", relPath)
145 return true
149 return true