Compare commits

..

No commits in common. "27c006019534d2a2bbd1c2852e4e2e58f51907dc" and "349936a9b4aede6ba5f0c5b3c89c7331b1843bc9" have entirely different histories.

4 changed files with 54 additions and 78 deletions

3
.gitignore vendored
View File

@ -1,5 +1,4 @@
cmd/bustled/bustled
cmd/bustle/bustle
bustle
*.swp
# ---> Go
# Binaries for programs and plugins

View File

@ -1,7 +0,0 @@
package main
import "fmt"
func main() {
fmt.Println("TODO bustle client")
}

View File

@ -1,69 +0,0 @@
package main
import (
"fmt"
"log"
"os"
"github.com/fsnotify/fsnotify"
)
func initHomeWatcher() (*fsnotify.Watcher, error) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
// TODO filepath.Walk over /home, adding to watcher
paths := []string{"/home/vilmibm", "/home/wren"}
for _, path := range paths {
err = watcher.Add(path)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to watch path %s: %w", path, err)
continue
}
}
return watcher, nil
}
func watchHome(watcher *fsnotify.Watcher) {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
log.Println("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
log.Println("error:", err)
}
}
}
func cli(args []string) int {
watcher, err := initHomeWatcher()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create watcher: %w", err)
return 1
}
defer watcher.Close()
// TODO have an event bus to write to
// TODO what is this done for do i need this done
done := make(chan bool)
go watchHome(watcher)
<-done
return 0
}
func main() {
os.Exit(cli(os.Args))
}

53
main.go 100644
View File

@ -0,0 +1,53 @@
package main
import (
"fmt"
"log"
"os"
"github.com/fsnotify/fsnotify"
)
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
log.Println("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
log.Println("error:", err)
}
}
}()
// will need to recursively watch for myself, including adding watchers for new directories D:
// check out filepath.Walk
for _, path := range os.Args[1:] {
err = watcher.Add(path)
if err != nil {
log.Fatal(err)
}
}
<-done
fmt.Println("hmm")
}