Compare commits
No commits in common. "27c006019534d2a2bbd1c2852e4e2e58f51907dc" and "349936a9b4aede6ba5f0c5b3c89c7331b1843bc9" have entirely different histories.
27c0060195
...
349936a9b4
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,5 +1,4 @@
|
|||||||
cmd/bustled/bustled
|
bustle
|
||||||
cmd/bustle/bustle
|
|
||||||
*.swp
|
*.swp
|
||||||
# ---> Go
|
# ---> Go
|
||||||
# Binaries for programs and plugins
|
# Binaries for programs and plugins
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("TODO bustle client")
|
|
||||||
}
|
|
@ -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
Normal file
53
main.go
Normal 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")
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user