26 lines
534 B
Go
26 lines
534 B
Go
package clip
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func WriteClipboard(ctx context.Context, text string) error {
|
|
if strings.TrimSpace(text) == "" {
|
|
return errors.New("empty transcript")
|
|
}
|
|
|
|
args := []string{"-selection", "clipboard", "-in", "-quiet", "-loops", "1"}
|
|
cmd := exec.CommandContext(ctx, "xclip", args...)
|
|
cmd.Stdin = strings.NewReader(text)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
if len(out) > 0 {
|
|
return errors.New(strings.TrimSpace(string(out)))
|
|
}
|
|
return err
|
|
}
|
|
return nil
|
|
}
|