1
0
Fork 0

Initial commit

This commit is contained in:
Gregory Eremin 2020-08-20 15:18:05 +02:00
commit 75c6d31127
3 changed files with 76 additions and 0 deletions

8
LICENSE Normal file
View File

@ -0,0 +1,8 @@
Copyright 2020 Gregory Eremin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

16
README.md Normal file
View File

@ -0,0 +1,16 @@
# wl-clipsync
Synchronizes clipboard and primary paste buffers.
Depends on [wl-clipboard](https://github.com/bugaevc/wl-clipboard).
## Installation
```
go get -u github.com/localhots/wl-clipwync
wl-clipsync &
```
# License
MIT

52
main.go Normal file
View File

@ -0,0 +1,52 @@
package main
import (
"fmt"
"flag"
"time"
"os/exec"
"bytes"
)
func main() {
interval := flag.Duration("i", 100*time.Millisecond, "Clipboard polling interval")
flag.Parse()
fmt.Println("Starting clipboard sync")
fmt.Println("Polling interval:", *interval)
var unified string
for range time.NewTicker(*interval).C {
primary := getVal("-p")
if primary != unified {
unified = primary
setVal(unified)
fmt.Println("Setting clip to", unified)
}
selection := getVal()
if selection != unified {
unified = selection
setVal(unified, "-p")
fmt.Println("Setting primary to", unified)
}
}
}
func getVal(args ...string) string {
args = append(args, "-n")
out, err := exec.Command("wl-paste", args...).Output()
if err != nil {
panic(err)
}
return string(out)
}
func setVal(val string, args... string) {
cmd := exec.Command("wl-copy")
cmd.Stdin = bytes.NewBufferString(val)
if err := cmd.Run(); err != nil {
panic(err)
}
}