mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-28 04:46:42 -04:00
29 lines
819 B
Go
29 lines
819 B
Go
//go:build windows || (linux && wsl)
|
|
|
|
package clip
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// CopyString copies a string to the clipboard.
|
|
func CopyString(clearClipboardAutomatically bool, copySubject string) error {
|
|
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", strings.ReplaceAll(copySubject, "'", "''")))
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
return errors.New("unable to copy to clipboard: " + err.Error())
|
|
}
|
|
if clearClipboardAutomatically {
|
|
LaunchClearProcess(copySubject)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// getClipCommands returns the commands for pasting and clearing the clipboard contents.
|
|
func getClipCommands() (*exec.Cmd, *exec.Cmd, error) {
|
|
return exec.Command("powershell.exe", "-c", "Get-Clipboard"), exec.Command("powershell.exe", "-c", "Set-Clipboard"), nil
|
|
}
|