From e1dea61d31a7e34bd86deb9e5206de1393668423 Mon Sep 17 00:00:00 2001 From: yory8 Date: Tue, 12 May 2020 15:49:29 +0200 Subject: [PATCH] fix: daemonize wl-copy --- CHANGELOG.md | 1 + main.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7339b6f..5a7367b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ **Notable bug fixes** +- wl-copy is now truly daemonized, allowing calling `alacritty -e sh -c clipman pick` - fzf couldn't recover the clipboard content in some cases # 1.5.1 diff --git a/main.go b/main.go index 78fef7d..d12b2c5 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "strings" + "syscall" "gopkg.in/alecthomas/kingpin.v2" ) @@ -178,8 +179,14 @@ func serveTxt(s string) { smartLog(fmt.Sprintf("couldn't find wl-copy: %v\n", err), "low", *alert) } + // daemonize wl-copy into a truly independent process + // necessary for running stuff like `alacritty -e sh -c clipman pick` + attr := &syscall.SysProcAttr{ + Setpgid: true, + } + // we mandate the mime type because we know we can only serve text; not doing this leads to weird bugs like #35 - cmd := exec.Cmd{Path: bin, Args: []string{bin, "-t", "TEXT"}, Stdin: strings.NewReader(s)} + cmd := exec.Cmd{Path: bin, Args: []string{bin, "-t", "TEXT"}, Stdin: strings.NewReader(s), SysProcAttr: attr} if err := cmd.Run(); err != nil { smartLog(fmt.Sprintf("error running wl-copy: %s\n", err), "low", *alert) }