mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-28 12:56:31 -04:00
28 lines
764 B
Go
28 lines
764 B
Go
//go:build windows || (linux && wsl)
|
|
|
|
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// copyString copies a string to the clipboard.
|
|
func copyString(continuous bool, copySubject string) {
|
|
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", strings.ReplaceAll(copySubject, "'", "''")))
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
PrintError("Failed to copy to clipboard: "+err.Error(), ErrorClipboard, true)
|
|
}
|
|
|
|
if !continuous {
|
|
LaunchClipClearProcess(copySubject)
|
|
}
|
|
}
|
|
|
|
// getClipCommands returns the commands for pasting and clearing the clipboard contents.
|
|
func getClipCommands() (*exec.Cmd, *exec.Cmd) {
|
|
return exec.Command("powershell.exe", "-c", "Get-Clipboard"), exec.Command("powershell.exe", "-c", "Set-Clipboard")
|
|
}
|