Add the keymap configuration file

This commit is contained in:
Aaron Fischer 2016-07-12 22:52:48 +02:00
parent 589bb9d144
commit e6bff5a4a4
2 changed files with 39 additions and 30 deletions

View file

@ -1,43 +1,51 @@
package main package main
import ( import (
"fmt" "fmt"
"log" "log"
"os"
"path"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
) )
func watchForConfigChanges() { func watchForConfigChanges() {
watcher, err := fsnotify.NewWatcher() watcher, err := fsnotify.NewWatcher()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer watcher.Close() defer watcher.Close()
done := make(chan bool) done := make(chan bool)
go func() { go func() {
for { for {
select { select {
case event := <-watcher.Events: case event := <-watcher.Events:
log.Println("event: ", event) log.Println("event: ", event)
if event.Op&fsnotify.Write == fsnotify.Write { if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name) log.Println("modified file:", event.Name)
} }
case err := <-watcher.Errors: case err := <-watcher.Errors:
log.Println("error:", err) log.Println("error:", err)
} }
} }
}() }()
// TODO: Add working directory // The configuration file need to be in the same directory as the binary.
err = watcher.Add("/tmp/test") // Later on, we can add other paths, where the file can be placed (like as a
if err != nil { // dotfile in the home directory or in the .config/n3rdpad/ folder or other
log.Fatal(err) // places where windows will put it).
} config_path, err := os.Getwd()
<-done 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() { func main() {
fmt.Printf("Ready\n") fmt.Printf("Ready\n")
watchForConfigChanges() watchForConfigChanges()
} }

1
keymap.conf Normal file
View file

@ -0,0 +1 @@
test