Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows wsl2 is slow with windows fallback binaries #85

Open
achan-godaddy opened this issue Feb 16, 2022 · 2 comments
Open

windows wsl2 is slow with windows fallback binaries #85

achan-godaddy opened this issue Feb 16, 2022 · 2 comments

Comments

@achan-godaddy
Copy link

achan-godaddy commented Feb 16, 2022

Not sure what has changed but unfortunately the binaries from win-clipboard are slower now, taking more than a few seconds where in the past it was much faster.

Perhaps we can use the os.release >= '5.10.60.1-microsoft-standard-WSL2' or just WSL2 to know when to use alternative binaries since these built in's should be supported on systems with wsl2.

The equivalent to the mac utils pbpaste in wsl/windows 10+ is:

#!/bin/bash
powershell.exe Get-Clipboard | sed 's/\r$//' | sed -z '$ s/\n$//'

We probably want to skip the sed to use the text as is.

and pbcopy (although clip.exe could may also be used directly without requiring tee that was more to emulate pbcopy's I believe)

#!/bin/bash
tee <&0 | clip.exe

Unfortunately can't submit a PR for this now but if this sounds good I may try to pick this up another time.

@Xiot
Copy link

Xiot commented Dec 2, 2022

I just noticed that its taking about 20s for the call to write to resolve on WSL2 for me.
Haven't dug too deep into it yet

@Xiot
Copy link

Xiot commented Dec 2, 2022

The way that I got around this was to pipe the data that I wanted to clip.exe directly.

const isWsl = require('is-wsl');
function copy(value) {
  if (!isWsl) {
    const clipboard = require('clipboardy');
    return clipboard.write(value);
  }

  return new Promise((resolve, reject) => {
    const child = require('child_process').exec(`echo -n '${value}' | clip.exe`);
    child.on('close', (code, sig) => {
      if (code === 0) {
        resolve();
      } else {
        reject(sig);
      }
    });
  });
}

There's probably a much better way to pipe the data and ensure that value is escaped properly, but this works in my case for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants