Persist a copy buffer after its source is gone
This commit is contained in:
parent
46c9a3c724
commit
981a591acd
3 changed files with 13 additions and 3 deletions
|
@ -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.
|
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`.
|
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`.
|
||||||
|
|
10
demon.go
10
demon.go
|
@ -42,7 +42,7 @@ func filter(history []string, text string) []string {
|
||||||
return history
|
return history
|
||||||
}
|
}
|
||||||
|
|
||||||
func listen(history []string, histfile string) error {
|
func listen(history []string, histfile string, persist bool) error {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
||||||
|
@ -85,6 +85,14 @@ func listen(history []string, histfile string) error {
|
||||||
return err
|
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
|
// writing to json is time consuming, so it's fine to sleep less and
|
||||||
// get ready to detect new events sooner.
|
// get ready to detect new events sooner.
|
||||||
// also because if we copied once, we might copy soon after.
|
// also because if we copied once, we might copy soon after.
|
||||||
|
|
4
main.go
4
main.go
|
@ -16,6 +16,7 @@ var (
|
||||||
app = kingpin.New("clipman", "A clipboard manager for Wayland")
|
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()
|
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()
|
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 (
|
var (
|
||||||
|
@ -44,7 +45,8 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *asDemon {
|
if *asDemon {
|
||||||
if err := listen(history, histfile); err != nil {
|
persist := !*noPersist
|
||||||
|
if err := listen(history, histfile, persist); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
} else if *asSelector {
|
} else if *asSelector {
|
||||||
|
|
Loading…
Reference in a new issue