Skip to content

Commit

Permalink
clipboard: added exec field which defaults to wl-copy
Browse files Browse the repository at this point in the history
  • Loading branch information
abenz1267 committed Oct 29, 2024
1 parent bd9937f commit 4b4b9ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions internal/config/config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"placeholder": "Windows"
},
"clipboard": {
"exec": "wl-copy",
"weight": 5,
"name": "clipboard",
"placeholder": "Clipboard",
Expand Down
5 changes: 3 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions internal/modules/clipboard/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Clipboard struct {
file string
imgTypes map[string]string
max int
exec string
}

type ClipboardItem struct {
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 4b4b9ee

Please sign in to comment.