Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/golang.org/x/net-0.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hazcod authored Oct 13, 2024
2 parents 71e761d + 059dbd4 commit 7a98345
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pkg/clipboard/clipboard_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package clipboard

import (
"fmt"
"os"
"os/exec"
)

// writes usinng the xclip command, might also
// work on freebsd and netbsd
func writeAll(text string) error {
path, err := exec.LookPath("xclip")
if err != nil {
return fmt.Errorf("failed to find xclip: %w", err)
}

r, w, err := os.Pipe()
if err != nil {
return fmt.Errorf("failed to create xclip pipe: %w", err)
}
var perr error
go func() {
_, err := w.WriteString(text)
if err != nil {
perr = fmt.Errorf("failed to write to xclip: %w", err)
}
w.Close() // ignore err
}()

c := exec.Cmd{
Path: path,
Args: []string{
"-i",
"-selection",
"clipboard",
},
Stdin: r,
Stdout: nil,
Stderr: nil,
}
err = c.Run()
if err != nil {
return fmt.Errorf("failed to run xclip: %w", err)
}
if perr != nil {
return fmt.Errorf("failed to write to xclip: %w", err)
}

return nil
}

0 comments on commit 7a98345

Please sign in to comment.