Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions v2/internal/frontend/desktop/darwin/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@
package darwin

import (
"os"
"os/exec"
)

// ensureUTF8Env returns the current environment with LANG set to en_US.UTF-8
// if it is not already set. This is needed because packaged macOS apps do not
// inherit the terminal's LANG variable, causing pbpaste/pbcopy to default to
// an ASCII-compatible encoding that mangles non-ASCII text.
func ensureUTF8Env() []string {
env := os.Environ()
if _, ok := os.LookupEnv("LANG"); !ok {
env = append(env, "LANG=en_US.UTF-8")
}
return env
}

func (f *Frontend) ClipboardGetText() (string, error) {
pasteCmd := exec.Command("pbpaste")
pasteCmd.Env = ensureUTF8Env()
out, err := pasteCmd.Output()
if err != nil {
return "", err
Expand All @@ -17,6 +31,7 @@ func (f *Frontend) ClipboardGetText() (string, error) {

func (f *Frontend) ClipboardSetText(text string) error {
copyCmd := exec.Command("pbcopy")
copyCmd.Env = ensureUTF8Env()
in, err := copyCmd.StdinPipe()
if err != nil {
return err
Expand Down