Persist a copy buffer after its source is gone

This commit is contained in:
yory8 2019-03-23 11:20:58 +01:00
parent 46c9a3c724
commit 981a591acd
3 changed files with 13 additions and 3 deletions

View file

@ -12,6 +12,6 @@ A basic clipboard manager for Wayland.
Install the binary in your path, then run it in your Sway session by adding `exec clipman -d` at the beginning of your config.
You can configure how many unique history items to preserve (default: 15) by editing directly the source.
You should edit `main.go` directly to configure how many unique history items to preserve (default: 15).
To query the history and select items, run the binary as `clipman -s`. You can assign it to a keybinding: `bindsym $mod+h exec clipman -s`.

View file

@ -42,7 +42,7 @@ func filter(history []string, text string) []string {
return history
}
func listen(history []string, histfile string) error {
func listen(history []string, histfile string, persist bool) error {
for {
@ -85,6 +85,14 @@ func listen(history []string, histfile string) error {
return err
}
if persist {
// make the copy buffer available to all applications,
// even when the source has disappeared
if err := exec.Command("wl-copy", text).Run(); err != nil {
return err
}
}
// writing to json is time consuming, so it's fine to sleep less and
// get ready to detect new events sooner.
// also because if we copied once, we might copy soon after.

View file

@ -16,6 +16,7 @@ var (
app = kingpin.New("clipman", "A clipboard manager for Wayland")
asDemon = app.Flag("demon", "Run as a demon to record clipboard events").Short('d').Default("false").Bool()
asSelector = app.Flag("select", "Select an item from clipboard history").Short('s').Default("false").Bool()
noPersist = app.Flag("no-persist", "Don't persist a copy buffer after a program exits").Short('P').Default("false").Bool()
)
var (
@ -44,7 +45,8 @@ func main() {
}
if *asDemon {
if err := listen(history, histfile); err != nil {
persist := !*noPersist
if err := listen(history, histfile, persist); err != nil {
log.Fatal(err)
}
} else if *asSelector {