Browse Source

Add the keymap configuration file

Aaron Fischer ago%!(EXTRA string=1 year %s)
parent
commit
e6bff5a4a4
2 changed files with 39 additions and 30 deletions
  1. 38 30
      agent.go
  2. 1 0
      keymap.conf

+ 38 - 30
agent.go View File

@@ -1,43 +1,51 @@
1 1
 package main
2 2
 
3 3
 import (
4
-  "fmt"
5
-  "log"
4
+	"fmt"
5
+	"log"
6
+	"os"
7
+	"path"
6 8
 
7
-  "github.com/fsnotify/fsnotify"
9
+	"github.com/fsnotify/fsnotify"
8 10
 )
9 11
 
10 12
 func watchForConfigChanges() {
11
-  watcher, err := fsnotify.NewWatcher()
12
-  if err != nil {
13
-    log.Fatal(err)
14
-  }
15
-  defer watcher.Close()
13
+	watcher, err := fsnotify.NewWatcher()
14
+	if err != nil {
15
+		log.Fatal(err)
16
+	}
17
+	defer watcher.Close()
16 18
 
17
-  done := make(chan bool)
18
-  go func() {
19
-    for {
20
-      select {
21
-      case event := <-watcher.Events:
22
-        log.Println("event: ", event)
23
-        if event.Op&fsnotify.Write == fsnotify.Write {
24
-          log.Println("modified file:", event.Name)
25
-        }
26
-      case err := <-watcher.Errors:
27
-        log.Println("error:", err)
28
-      }
29
-    }
30
-  }()
19
+	done := make(chan bool)
20
+	go func() {
21
+		for {
22
+			select {
23
+			case event := <-watcher.Events:
24
+				log.Println("event: ", event)
25
+				if event.Op&fsnotify.Write == fsnotify.Write {
26
+					log.Println("modified file:", event.Name)
27
+				}
28
+			case err := <-watcher.Errors:
29
+				log.Println("error:", err)
30
+			}
31
+		}
32
+	}()
31 33
 
32
-  // TODO: Add working directory
33
-  err = watcher.Add("/tmp/test")
34
-  if err != nil {
35
-    log.Fatal(err)
36
-  }
37
-  <-done
34
+	// The configuration file need to be in the same directory as the binary.
35
+	// Later on, we can add other paths, where the file can be placed (like as a
36
+	// dotfile in the home directory or in the .config/n3rdpad/ folder or other
37
+	// places where windows will put it).
38
+	config_path, err := os.Getwd()
39
+	config_file := path.Join(config_path, "keymap.conf")
40
+
41
+	err = watcher.Add(config_file)
42
+	if err != nil {
43
+		log.Fatal("Can't find the 'keymap.conf' configuration file. Please create one.")
44
+	}
45
+	<-done
38 46
 }
39 47
 
40 48
 func main() {
41
-  fmt.Printf("Ready\n")
42
-  watchForConfigChanges()
49
+	fmt.Printf("Ready\n")
50
+	watchForConfigChanges()
43 51
 }

+ 1 - 0
keymap.conf View File

@@ -0,0 +1 @@
1
+test