Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement clipboard using xclip to support openbsd #138

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading