Fix bug, wrap debug logs
This commit is contained in:
parent
75c6d31127
commit
b0cb3723f9
28
main.go
28
main.go
|
@ -6,11 +6,14 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
interval := flag.Duration("i", 100*time.Millisecond, "Clipboard polling interval")
|
interval := flag.Duration("i", 100*time.Millisecond, "Clipboard polling interval")
|
||||||
|
debug := flag.Bool("d", false, "Debug output")
|
||||||
|
lotsofDebug := flag.Bool("dd", false, "Full debug")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
fmt.Println("Starting clipboard sync")
|
fmt.Println("Starting clipboard sync")
|
||||||
|
@ -19,34 +22,43 @@ func main() {
|
||||||
var unified string
|
var unified string
|
||||||
for range time.NewTicker(*interval).C {
|
for range time.NewTicker(*interval).C {
|
||||||
primary := getVal("-p")
|
primary := getVal("-p")
|
||||||
if primary != unified {
|
if *lotsofDebug {
|
||||||
|
log.Println("Primary:", primary)
|
||||||
|
}
|
||||||
|
if primary != "" && primary != unified {
|
||||||
unified = primary
|
unified = primary
|
||||||
setVal(unified)
|
setVal(unified)
|
||||||
|
if *debug {
|
||||||
fmt.Println("Setting clip to", unified)
|
fmt.Println("Setting clip to", unified)
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
selection := getVal()
|
selection := getVal()
|
||||||
if selection != unified {
|
if *lotsofDebug {
|
||||||
|
log.Println("Selection:", primary)
|
||||||
|
}
|
||||||
|
if selection != "" && selection != unified {
|
||||||
unified = selection
|
unified = selection
|
||||||
setVal(unified, "-p")
|
setVal(unified, "-p")
|
||||||
|
if *debug {
|
||||||
fmt.Println("Setting primary to", unified)
|
fmt.Println("Setting primary to", unified)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getVal(args ...string) string {
|
func getVal(args ...string) string {
|
||||||
args = append(args, "-n")
|
args = append(args, "-n")
|
||||||
out, err := exec.Command("wl-paste", args...).Output()
|
out, _ := exec.Command("wl-paste", args...).Output()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return string(out)
|
return string(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setVal(val string, args... string) {
|
func setVal(val string, args... string) {
|
||||||
cmd := exec.Command("wl-copy")
|
cmd := exec.Command("wl-copy", args...)
|
||||||
cmd.Stdin = bytes.NewBufferString(val)
|
cmd.Stdin = bytes.NewBufferString(val)
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
panic(err)
|
log.Printf("Failed to get paste buffer value (%v): %v", args, err)
|
||||||
|
log.Printf("Value in question: %q", val)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue