diff --git a/app.go b/app.go index 8fd2066f..01ecce3c 100644 --- a/app.go +++ b/app.go @@ -427,7 +427,7 @@ func (app *app) loop() { } } - app.setWatchPaths() + app.addWatchPaths() app.ui.draw(app.nav) case r := <-app.nav.regChan: @@ -442,12 +442,7 @@ func (app *app) loop() { app.ui.draw(app.nav) case f := <-app.nav.fileChan: - dirs := app.nav.dirs - if app.ui.dirPrev != nil { - dirs = append(dirs, app.ui.dirPrev) - } - - for _, dir := range dirs { + for _, dir := range app.nav.dirCache { if dir.path != filepath.Dir(f.path) { continue } @@ -638,7 +633,7 @@ func (app *app) runShell(s string, args []string, prefix string) { } } -func (app *app) setWatchPaths() { +func (app *app) addWatchPaths() { if !gOpts.watch || len(app.nav.dirs) == 0 { return } @@ -654,5 +649,5 @@ func (app *app) setWatchPaths() { } } - app.watch.set(paths) + app.watch.add(paths) } diff --git a/eval.go b/eval.go index 91df3268..ecd5a05d 100644 --- a/eval.go +++ b/eval.go @@ -195,7 +195,7 @@ func (e *setExpr) eval(app *app, args []string) { if err == nil { if gOpts.watch { app.watch.start() - app.setWatchPaths() + app.addWatchPaths() } else { app.watch.stop() } @@ -582,7 +582,7 @@ func preChdir(app *app) { func onChdir(app *app) { app.nav.addJumpList() - app.setWatchPaths() + app.addWatchPaths() if cmd, ok := gOpts.cmds["on-cd"]; ok { cmd.eval(app, nil) } diff --git a/go.mod b/go.mod index cb9a01d8..a5899036 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23 require ( github.com/Xuanwo/go-locale v1.1.2 github.com/djherbis/times v1.6.0 - github.com/fsnotify/fsnotify v1.7.0 + github.com/fsnotify/fsnotify v1.8.0 github.com/gdamore/tcell/v2 v2.7.4 github.com/mattn/go-runewidth v0.0.16 golang.org/x/sys v0.28.0 @@ -14,7 +14,7 @@ require ( ) require ( - github.com/gdamore/encoding v1.0.0 // indirect + github.com/gdamore/encoding v1.0.1 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/rivo/uniseg v0.4.3 // indirect + github.com/rivo/uniseg v0.4.7 // indirect ) diff --git a/go.sum b/go.sum index 568b2feb..4a4eae08 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,12 @@ github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c= github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= +github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= +github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw= +github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo= github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU= github.com/gdamore/tcell/v2 v2.7.4/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -16,6 +20,8 @@ github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw= github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= diff --git a/watch.go b/watch.go index 269a4636..1fcfb684 100644 --- a/watch.go +++ b/watch.go @@ -64,19 +64,16 @@ func (watch *watch) stop() { watch.events = nil } -func (watch *watch) set(paths map[string]bool) { +func (watch *watch) add(paths map[string]bool) { if watch.watcher == nil { return } - for _, path := range watch.watcher.WatchList() { - if !paths[path] { - watch.watcher.Remove(path) - } - } - for path := range paths { - watch.watcher.Add(path) + // ignore /dev since write updates to /dev/tty causes high cpu usage + if path != "/dev" { + watch.watcher.Add(path) + } } }