clipboard icon indicating copy to clipboard operation
clipboard copied to clipboard

Windows Subsystem for Linux support

Open rianadon opened this issue 4 years ago • 5 comments

It would be awesome if executing clip.exe was used as an additional fallback on Linux. That way, in WSL environments where xclip and xsel are not installed, text could be copied to the Windows clipboard. Specifically, I'm trying to use gopass (which uses this library) under WSL.

In cases where someone is running an X server on WSL, the situation gets complicated unfortunately.

rianadon avatar Aug 15 '19 23:08 rianadon

not pretty but this is just an one minute hack

	var clipPath string
	if _, err := os.Stat("/c/Windows/system32/clip.exe"); !os.IsNotExist(err) {
		clipPath = "/c/Windows/system32/clip.exe"
	} else if _, err := os.Stat("/mnt/c/Windows/system32/clip.exe"); !os.IsNotExist(err) {
		clipPath = "/mnt/c/Windows/system32/clip.exe"
	} else

	p := fmt.Sprintf("Bearer %s\n", re.IdToken)
	if clipPath != "" {
		sh.Run("bash", "-c", fmt.Sprintf("echo '%s' | %s", p, clipPath))
	}
```

k1ng440 avatar Feb 05 '20 01:02 k1ng440

I'm tempted to take a stab at this; hub also uses this library.

@atotto Would a PR that looks for clip.exe on Linux be accepted (assuming code quality is OK etc, of course)?

tomasaschan avatar Nov 05 '20 10:11 tomasaschan

This would also solve https://github.com/gopasspw/gopass/issues/1664 on our side 👍

AnomalRoil avatar Jan 07 '21 18:01 AnomalRoil

This is what I've done in the past to get around this: https://github.com/e-zk/cpass/blob/master/main.go#L53

Checking the version string in /proc for "microsoft-standard"^1 may not be the most robust solution for checking whether the distro is WSL.

e-zk avatar Jan 13 '21 06:01 e-zk

This works better with WSL https://github.com/golang-design/clipboard

mikutas avatar Sep 21 '22 23:09 mikutas