diff --git a/agent.go b/agent.go index e9cb809..be673a1 100644 --- a/agent.go +++ b/agent.go @@ -1,43 +1,51 @@ package main import ( - "fmt" - "log" + "fmt" + "log" + "os" + "path" - "github.com/fsnotify/fsnotify" + "github.com/fsnotify/fsnotify" ) func watchForConfigChanges() { - watcher, err := fsnotify.NewWatcher() - if err != nil { - log.Fatal(err) - } - defer watcher.Close() + watcher, err := fsnotify.NewWatcher() + if err != nil { + log.Fatal(err) + } + defer watcher.Close() - done := make(chan bool) - go func() { - for { - select { - case event := <-watcher.Events: - log.Println("event: ", event) - if event.Op&fsnotify.Write == fsnotify.Write { - log.Println("modified file:", event.Name) - } - case err := <-watcher.Errors: - log.Println("error:", err) - } - } - }() + done := make(chan bool) + go func() { + for { + select { + case event := <-watcher.Events: + log.Println("event: ", event) + if event.Op&fsnotify.Write == fsnotify.Write { + log.Println("modified file:", event.Name) + } + case err := <-watcher.Errors: + log.Println("error:", err) + } + } + }() - // TODO: Add working directory - err = watcher.Add("/tmp/test") - if err != nil { - log.Fatal(err) - } - <-done + // The configuration file need to be in the same directory as the binary. + // Later on, we can add other paths, where the file can be placed (like as a + // dotfile in the home directory or in the .config/n3rdpad/ folder or other + // places where windows will put it). + config_path, err := os.Getwd() + config_file := path.Join(config_path, "keymap.conf") + + err = watcher.Add(config_file) + if err != nil { + log.Fatal("Can't find the 'keymap.conf' configuration file. Please create one.") + } + <-done } func main() { - fmt.Printf("Ready\n") - watchForConfigChanges() + fmt.Printf("Ready\n") + watchForConfigChanges() } diff --git a/keymap.conf b/keymap.conf new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/keymap.conf @@ -0,0 +1 @@ +test \ No newline at end of file