# HG changeset patch # User Sean E. Russell # Date 1586111141 18000 # Sun Apr 05 13:25:41 2020 -0500 # Node ID eae907dbb9e983ba72f4773d5b067b98273cce6c # Parent b0123d3922d36bf69fa0391075396249abc288e7 Adds some better debugging. diff --git a/main.go b/main.go --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ 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 \n", os.Args[0]) @@ -79,7 +80,9 @@ 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 @@ 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 @@ 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) + } } } } diff --git a/rules.json b/rules.json --- a/rules.json +++ b/rules.json @@ -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"] ] } ]