From 3d03cd40d6193216750df0153014b9ec3297b061 Mon Sep 17 00:00:00 2001 From: zhihao <952331408@qq.com> Date: Fri, 4 Apr 2025 21:01:32 +0800 Subject: [PATCH 1/3] strip Windows \r --- uniclip.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uniclip.go b/uniclip.go index 8d131a6..8da9a6e 100644 --- a/uniclip.go +++ b/uniclip.go @@ -355,7 +355,7 @@ func runGetClipCommand() string { return "An error occurred wile getting the local clipboard" } if runtime.GOOS == "windows" { - return strings.TrimSuffix(string(out), "\r\n") // powershell's get-clipboard adds a windows newline to the end for some reason + return strings.ReplaceAll(string(out), "\r\n", "\n") // powershell's get-clipboard adds a windows newline to the end for some reason } return string(out) } From 2b86f16752011721e31a623e97775cfda9947926 Mon Sep 17 00:00:00 2001 From: zhihao <952331408@qq.com> Date: Wed, 2 Jul 2025 18:01:48 +0800 Subject: [PATCH 2/3] add -r for uniclip to remove tailing newline --- uniclip.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/uniclip.go b/uniclip.go index 8da9a6e..8c6d0cf 100644 --- a/uniclip.go +++ b/uniclip.go @@ -10,7 +10,6 @@ import ( "encoding/gob" "errors" "fmt" - "golang.org/x/crypto/ssh/terminal" "io" "io/ioutil" "net" @@ -22,6 +21,8 @@ import ( "syscall" "time" + "golang.org/x/crypto/ssh/terminal" + "golang.org/x/crypto/scrypt" ) @@ -338,7 +339,7 @@ func runGetClipCommand() string { cmd = exec.Command("powershell.exe", "-command", "Get-Clipboard") default: if _, err = exec.LookPath("xclip"); err == nil { - cmd = exec.Command("xclip", "-out", "-selection", "clipboard") + cmd = exec.Command("xclip", "-r", "-out", "-selection", "clipboard") } else if _, err = exec.LookPath("xsel"); err == nil { cmd = exec.Command("xsel", "--output", "--clipboard") } else if _, err = exec.LookPath("wl-paste"); err == nil { @@ -355,7 +356,7 @@ func runGetClipCommand() string { return "An error occurred wile getting the local clipboard" } if runtime.GOOS == "windows" { - return strings.ReplaceAll(string(out), "\r\n", "\n") // powershell's get-clipboard adds a windows newline to the end for some reason + return strings.TrimSuffix(string(out), "\r\n") // powershell's get-clipboard adds a windows newline to the end for some reason } return string(out) } @@ -377,7 +378,7 @@ func setLocalClip(s string) { copyCmd = exec.Command("clip") default: if _, err := exec.LookPath("xclip"); err == nil { - copyCmd = exec.Command("xclip", "-in", "-selection", "clipboard") + copyCmd = exec.Command("xclip", "-r", "-in", "-selection", "clipboard") } else if _, err = exec.LookPath("xsel"); err == nil { copyCmd = exec.Command("xsel", "--input", "--clipboard") } else if _, err = exec.LookPath("wl-copy"); err == nil { From 445c138bb13749451d371d1c6412dc857ca07a4e Mon Sep 17 00:00:00 2001 From: zhihao <952331408@qq.com> Date: Fri, 4 Jul 2025 17:24:14 +0800 Subject: [PATCH 3/3] transfer \r\n to \n --- uniclip.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/uniclip.go b/uniclip.go index 8c6d0cf..b318581 100644 --- a/uniclip.go +++ b/uniclip.go @@ -339,7 +339,7 @@ func runGetClipCommand() string { cmd = exec.Command("powershell.exe", "-command", "Get-Clipboard") default: if _, err = exec.LookPath("xclip"); err == nil { - cmd = exec.Command("xclip", "-r", "-out", "-selection", "clipboard") + cmd = exec.Command("xclip", "-out", "-selection", "clipboard") } else if _, err = exec.LookPath("xsel"); err == nil { cmd = exec.Command("xsel", "--output", "--clipboard") } else if _, err = exec.LookPath("wl-paste"); err == nil { @@ -356,7 +356,9 @@ func runGetClipCommand() string { return "An error occurred wile getting the local clipboard" } if runtime.GOOS == "windows" { - return strings.TrimSuffix(string(out), "\r\n") // powershell's get-clipboard adds a windows newline to the end for some reason + str := string(out) + str = strings.ReplaceAll(str, "\r\n", "\n") // powershell's get-clipboard transfers "\n" to "\r\n" and adds a windows newline "\r\n" to the end for some reason, so transfer it back + return strings.TrimSuffix(str, "\n") } return string(out) } @@ -378,7 +380,7 @@ func setLocalClip(s string) { copyCmd = exec.Command("clip") default: if _, err := exec.LookPath("xclip"); err == nil { - copyCmd = exec.Command("xclip", "-r", "-in", "-selection", "clipboard") + copyCmd = exec.Command("xclip", "-in", "-selection", "clipboard") } else if _, err = exec.LookPath("xsel"); err == nil { copyCmd = exec.Command("xsel", "--input", "--clipboard") } else if _, err = exec.LookPath("wl-copy"); err == nil { @@ -435,7 +437,8 @@ func handleError(err error) { func debug(a ...interface{}) { if printDebugInfo { - fmt.Println("verbose:", a) + // fmt.Println("verbose:", a) + fmt.Printf("%q\n", fmt.Sprint(a)) } }