Add cross-platform clipboard support

Implement CopyFile for darwin, linux, and windows and call it from
main to copy generated output to the clipboard. Enable CGO for builds,
update goreleaser and release workflow to use macOS, and add a
cross-platform test workflow that verifies the clipboard.
This commit is contained in:
2026-01-31 01:53:12 +01:00
parent fd5c8d72f5
commit af9e0a5372
7 changed files with 248 additions and 5 deletions
+38
View File
@@ -0,0 +1,38 @@
//go:build linux
package clipboard
import (
"fmt"
"os/exec"
"path/filepath"
"strings"
)
func CopyFile(path string) error {
absPath, err := filepath.Abs(path)
if err != nil {
return err
}
uri := fmt.Sprintf("file://%s", absPath)
if isCommandAvailable("wl-copy") {
cmd := exec.Command("wl-copy", "--type", "text/uri-list")
cmd.Stdin = strings.NewReader(uri)
return cmd.Run()
}
if isCommandAvailable("xclip") {
cmd := exec.Command("xclip", "-selection", "clipboard", "-t", "text/uri-list")
cmd.Stdin = strings.NewReader(uri)
return cmd.Run()
}
return fmt.Errorf("install 'wl-copy' or 'xclip'")
}
func isCommandAvailable(name string) bool {
_, err := exec.LookPath(name)
return err == nil
}