Skip to content

Commit 1e5ff20

Browse files
committed
fix(actions): Improve clipboard operations with direct buffer input
- Replace echo command piping with bytes.NewBufferString for clipboard operations on Darwin - Replace echo command piping with bytes.NewBufferString for clipboard operations on Linux - Remove unused "fmt" import from actions_linux.go - Add "bytes" import to both platform-specific action files - Simplify stdin handling by using direct buffer instead of spawning echo subprocess - Improves performance and reduces subprocess overhead for clipboard operations
1 parent 2c66afb commit 1e5ff20

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

actions_darwin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import (
7+
"bytes"
78
"fmt"
89
"os/exec"
910
)
@@ -21,7 +22,7 @@ func (as *ActionService) OpenURL(url string) error {
2122

2223
func (as *ActionService) SetClipboard(content string) error {
2324
cmd := exec.Command("pbcopy")
24-
cmd.Stdin = exec.Command("echo", "-n", content).Stdout
25+
cmd.Stdin = bytes.NewBufferString(content)
2526
return cmd.Run()
2627
}
2728

actions_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package main
55

66
import (
7-
"fmt"
7+
"bytes"
88
"os/exec"
99
)
1010

@@ -22,12 +22,12 @@ func (as *ActionService) OpenURL(url string) error {
2222
func (as *ActionService) SetClipboard(content string) error {
2323
// Try xclip first, then xsel as fallback
2424
cmd := exec.Command("xclip", "-selection", "clipboard")
25-
cmd.Stdin = exec.Command("echo", "-n", content).Stdout
25+
cmd.Stdin = bytes.NewBufferString(content)
2626
err := cmd.Run()
2727
if err != nil {
2828
// Fallback to xsel
2929
cmd = exec.Command("xsel", "--clipboard", "--input")
30-
cmd.Stdin = exec.Command("echo", "-n", content).Stdout
30+
cmd.Stdin = bytes.NewBufferString(content)
3131
return cmd.Run()
3232
}
3333
return nil

0 commit comments

Comments
 (0)