v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-16 07:40:44 -07:00

feat: Added X11/Wayland detection for copy command (#10)

This commit is contained in:
muvment 2023-02-03 06:07:51 +01:00 committed by GitHub
parent 25b20b9f14
commit 8f2b3167d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"os/exec"
"runtime"
)
@ -22,9 +23,16 @@ func SetTermTitle(title string) {
func CopyToClipboard(text string) {
switch runtime.GOOS {
case "linux":
exec.Command("sh", "-c",
switch os.Getenv("XDG_SESSION_TYPE") {
case "x11":
exec.Command("sh", "-c",
fmt.Sprintf("echo -n '%s' | xclip -selection clipboard", text)).
Start()
case "wayland":
exec.Command("sh", "-c",
fmt.Sprintf("echo -n '%s' | wl-copy", text)).
Start()
}
case "darwin":
exec.Command("sh", "-c",
fmt.Sprintf("echo -n '%s' | pbcopy", text)).