diff --git a/README.md b/README.md index c186481..00e4418 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/demon.go b/demon.go index 01f7128..16fed38 100644 --- a/demon.go +++ b/demon.go @@ -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. diff --git a/main.go b/main.go index 4c4f534..0afa085 100644 --- a/main.go +++ b/main.go @@ -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 {