Skip to content

Commit 3e865a2

Browse files
committed
change default watch behavior
1 parent 44efdb9 commit 3e865a2

5 files changed

Lines changed: 31 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type Config struct {
6161
type Ignore struct {
6262
Dir []string `toml:"dir" yaml:"dir"` // Directories to ignore, e.g. node_modules
6363
File []string `toml:"file" yaml:"file"` // Files to ignore
64-
WatchedExten []string `toml:"watched_extension" yaml:"watched_extension"` // Extensions to watch; anything else is ignored. Empty watches all files.
64+
WatchedExten []string `toml:"watched_extension" yaml:"watched_extension"` // Extensions to watch; anything else is ignored. Use "*" to watch all files; empty watches nothing.
6565
IgnoreGit bool `toml:"git" yaml:"git"` // When true, .gitignore entries in the root are also ignored
6666
}
6767

cmd/refresh/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func parseFlags(args []string) (cliFlags, error) {
3737
fs.StringVar(&f.configPath, "f", "", "Config file to read (.toml or .yaml)")
3838
fs.StringVar(&f.ignoreDir, "id", "", "Ignore directories (comma-separated)")
3939
fs.StringVar(&f.ignoreFile, "if", "", "Ignore files (comma-separated)")
40-
fs.StringVar(&f.ignoreExt, "ie", "", "Watched extensions (comma-separated)")
40+
fs.StringVar(&f.ignoreExt, "ie", "*", "Watched extensions (comma-separated; \"*\" watches all, empty watches nothing)")
4141
fs.IntVar(&f.debounce, "d", 1000, "Debounce time in milliseconds")
4242
fs.BoolVar(&f.version, "v", false, "Print version")
4343
fs.BoolVar(&f.gitIgnore, "git", false, "Read .gitignore in the root")

engine/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ func DefaultEngineConfig() Config {
4747
LogLevel: "warn",
4848
Debounce: 1000,
4949
Ignore: Ignore{
50-
Dir: []string{".git", ".idea", ".node_modules", "vendor"},
51-
File: []string{".DS_Store", ".gitignore", ".gitkeep"},
52-
IgnoreGit: true,
50+
Dir: []string{".git", ".idea", ".node_modules", "vendor"},
51+
File: []string{".DS_Store", ".gitignore", ".gitkeep"},
52+
WatchedExten: []string{"*"},
53+
IgnoreGit: true,
5354
},
5455
ExecStruct: make([]process.Execute, 0),
5556
}

engine/ignore.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,17 @@ func (i *Ignore) shouldIgnore(path string) bool {
3232
}
3333

3434
func (i *Ignore) isWatchedExtension(path string) bool {
35-
// No configured filter means watch everything; this is the default config
36-
// and the bare-CLI case, so it must reload rather than ignore every change.
35+
// An empty filter means watch nothing: it is the off-switch users reach for
36+
// by leaving watched_extension blank/commented out. Watch-all is opt-in via
37+
// an explicit "*" entry (matched through patternMatch below), which the
38+
// bare-CLI and default-config cases set so they still reload.
3739
if len(i.WatchedExten) == 0 {
40+
return false
41+
}
42+
43+
// "*" is the explicit watch-all token; match every path, including those
44+
// without an extension.
45+
if slices.Contains(i.WatchedExten, "*") {
3846
return true
3947
}
4048

engine/ignore_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,27 @@ func Test_isWatchedExtension(t *testing.T) {
7777
wantIsWatched: false,
7878
},
7979
{
80-
name: "empty filter watches all extensions (default config)",
80+
name: "empty filter watches nothing (off-switch)",
8181
path: "/some/path/file.go",
8282
watchedExten: nil,
83-
wantIsWatched: true,
83+
wantIsWatched: false,
8484
},
8585
{
86-
name: "empty filter watches extensionless files too",
86+
name: "empty filter watches nothing, extensionless too",
8787
path: "/some/path/Makefile",
8888
watchedExten: nil,
89+
wantIsWatched: false,
90+
},
91+
{
92+
name: "star watches all extensions",
93+
path: "/some/path/file.go",
94+
watchedExten: []string{"*"},
95+
wantIsWatched: true,
96+
},
97+
{
98+
name: "star watches extensionless files too",
99+
path: "/some/path/Makefile",
100+
watchedExten: []string{"*"},
89101
wantIsWatched: true,
90102
},
91103
}

0 commit comments

Comments
 (0)