diff --git a/README.md b/README.md index 00e4418..5b4011c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,4 @@ 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 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 16fed38..2795825 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, persist bool) error { +func listen(history []string, histfile string, persist bool, max int) error { for { diff --git a/main.go b/main.go index 0afa085..627293d 100644 --- a/main.go +++ b/main.go @@ -10,13 +10,12 @@ import ( "gopkg.in/alecthomas/kingpin.v2" ) -const max = 15 - 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() + max = app.Flag("max-items", "How many copy items to store in history").Default("15").Int() ) var ( @@ -46,11 +45,11 @@ func main() { if *asDemon { persist := !*noPersist - if err := listen(history, histfile, persist); err != nil { + if err := listen(history, histfile, persist, *max); err != nil { log.Fatal(err) } } else if *asSelector { - if err := selector(history); err != nil { + if err := selector(history, *max); err != nil { log.Fatal(err) } } diff --git a/selector.go b/selector.go index 1f5da5e..b4afabd 100644 --- a/selector.go +++ b/selector.go @@ -7,7 +7,7 @@ import ( "strings" ) -func selector(history []string) error { +func selector(history []string, max int) error { // reverse the history for i, j := 0, len(history)-1; i < j; i, j = i+1, j-1 {