Adds some better debugging.
2 files changed, 31 insertions(+), 12 deletions(-)

M main.go
M rules.json
M main.go +29 -10
@@ 22,6 22,7 @@ var Version, BuildDate string = "dev", "
 func main() {
 	help := flag.Bool("h", false, "Print help and exit")
 	version := flag.Bool("v", false, "Print version and exit")
+	verbose := flag.Bool("V", false, "Be chatty")
 	debug := flag.Bool("d", false, "Print matches, but don't execute commands")
 	flag.Parse()
 	usage := fmt.Sprintf("USAGE: %s <rules-file>\n", os.Args[0])

          
@@ 79,7 80,9 @@ func main() {
 	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
 	go func() {
 		<-signals
-		log.Println("Exiting monitor mode...")
+		if *verbose {
+			log.Println("Exiting monitor mode...")
+		}
 		quit <- struct{}{}
 		os.Exit(0)
 	}()

          
@@ 93,7 96,9 @@ func main() {
 	if len(ruleset.Rules) > 1 {
 		plural = "s"
 	}
-	log.Printf("monitoring for connection events for %d rule%s", len(ruleset.Rules), plural)
+	if *verbose {
+		log.Printf("monitoring for connection events for %d rule%s", len(ruleset.Rules), plural)
+	}
 	for {
 		select {
 		case evt := <-queue:

          
@@ 101,18 106,32 @@ func main() {
 			if rule != nil {
 				var cmd *exec.Cmd
 				for _, cx := range rule.Run {
-					log.Printf("%s: %v\n", evt.Env["NAME"], cx)
-					if *debug {
-						continue
-					}
-					if flag.NArg() > 1 {
+					if len(cx) > 1 {
 						cmd = exec.Command(cx[0], cx[1:]...)
 					} else {
 						cmd = exec.Command(cx[0])
 					}
-					err := cmd.Run()
-					if err != nil {
-						panic(err)
+					if *verbose {
+						log.Printf("%s: %v\n", evt.Env["NAME"], cmd.String())
+					}
+					if *debug {
+						log.Printf("Event:\n%s", evt)
+						log.Printf("debug NOP")
+						continue
+					}
+					if *verbose {
+						bs, err := cmd.CombinedOutput()
+						if err != nil {
+							panic(err)
+						}
+						if len(bs) > 0 {
+							log.Printf("%s\n", string(bs))
+						}
+					} else {
+						err := cmd.Run()
+						if err != nil {
+							panic(err)
+						}
 					}
 				}
 			}

          
M rules.json +2 -2
@@ 5,10 5,10 @@ 
 			"env": {
 				"ACTION": "add",
 				"SUBSYSTEM": "input",
-				"NAME": ".*Goldtouch.*Keyboard.*System Control"
+				"NAME": ".*Goldtouch Bluetooth Keyboard.*"
 			},
 			"run": [
-				["setxkbmap", "-layout","us","-variant","dvorak","-geometry","kinesis","-option","caps:super","-option","compose:lwin"]
+				["setxkbmap", "-v", "10", "-layout","us","-variant","dvorak","-geometry","kinesis","-option","caps:super","-option","compose:lwin"]
 			]
 		}
 	]