From 8f2b3167d6792c1b3e93d131fd555385e0ededb9 Mon Sep 17 00:00:00 2001 From: muvment <107356094+muvment@users.noreply.github.com> Date: Fri, 3 Feb 2023 06:07:51 +0100 Subject: [PATCH] feat: Added X11/Wayland detection for copy command (#10) --- utils.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/utils.go b/utils.go index fcce677..ebe96b0 100644 --- a/utils.go +++ b/utils.go @@ -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)).