From 4b4b9eea017805d720ceb1ad974caf47e554b47b Mon Sep 17 00:00:00 2001 From: Andrej Benz Date: Tue, 29 Oct 2024 18:16:14 +0100 Subject: [PATCH] clipboard: added `exec` field which defaults to `wl-copy` --- internal/config/config.default.json | 1 + internal/config/config.go | 5 +++-- internal/modules/clipboard/clipboard.go | 12 +++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/config/config.default.json b/internal/config/config.default.json index a816e00..8f69743 100644 --- a/internal/config/config.default.json +++ b/internal/config/config.default.json @@ -44,6 +44,7 @@ "placeholder": "Windows" }, "clipboard": { + "exec": "wl-copy", "weight": 5, "name": "clipboard", "placeholder": "Clipboard", diff --git a/internal/config/config.go b/internal/config/config.go index efcd1ff..c1ae4f8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -147,8 +147,9 @@ type ActivationMode struct { type Clipboard struct { GeneralModule `mapstructure:",squash"` - ImageHeight int `mapstructure:"image_height"` - MaxEntries int `mapstructure:"max_entries"` + ImageHeight int `mapstructure:"image_height"` + MaxEntries int `mapstructure:"max_entries"` + Exec string `mapstructure:"exec"` } type Dmenu struct { diff --git a/internal/modules/clipboard/clipboard.go b/internal/modules/clipboard/clipboard.go index 34b77f1..0be50de 100644 --- a/internal/modules/clipboard/clipboard.go +++ b/internal/modules/clipboard/clipboard.go @@ -26,6 +26,7 @@ type Clipboard struct { file string imgTypes map[string]string max int + exec string } type ClipboardItem struct { @@ -60,6 +61,7 @@ func (c *Clipboard) Setup(cfg *config.Config) bool { c.file = filepath.Join(util.CacheDir(), "clipboard.gob") c.max = cfg.Builtins.Clipboard.MaxEntries + c.exec = cfg.Builtins.Clipboard.Exec c.imgTypes = make(map[string]string) c.imgTypes["image/png"] = "png" @@ -78,7 +80,7 @@ func (c *Clipboard) SetupData(cfg *config.Config, ctx context.Context) { c.items = clean(current, c.file) for _, v := range c.items { - c.entries = append(c.entries, itemToEntry(v)) + c.entries = append(c.entries, itemToEntry(v, c.exec)) } c.general.IsSetup = true @@ -197,7 +199,7 @@ func (c *Clipboard) watch() { cmd.Start() } - c.entries = append([]util.Entry{itemToEntry(e)}, c.entries...) + c.entries = append([]util.Entry{itemToEntry(e, c.exec)}, c.entries...) c.items = append([]ClipboardItem{e}, c.items...) if len(c.items) >= c.max { @@ -212,11 +214,11 @@ func (c *Clipboard) watch() { } } -func itemToEntry(item ClipboardItem) util.Entry { +func itemToEntry(item ClipboardItem, exec string) util.Entry { entry := util.Entry{ Label: strings.TrimSpace(item.Content), Sub: "Text", - Exec: "wl-copy", + Exec: exec, Piped: util.Piped{Content: item.Content, Type: "string"}, Categories: []string{"clipboard"}, Class: "clipboard", @@ -228,7 +230,7 @@ func itemToEntry(item ClipboardItem) util.Entry { if item.IsImg { entry.Label = "Image" entry.Image = item.Content - entry.Exec = "wl-copy" + entry.Exec = exec entry.Piped = util.Piped{ Content: item.Content, Type: "file",