diff options
author | 2024-09-13 12:45:30 +0100 | |
---|---|---|
committer | 2024-09-13 13:45:30 +0200 | |
commit | 06eff60cabb55d91fe4075421b1693b1ab33225c (patch) | |
tree | f78c4be760c50e83c84284ce7bd373a476c10b2f | |
parent | 490eed1cd948f91aedf86b5ffd4ac7285ee52f40 (diff) | |
download | astro-06eff60cabb55d91fe4075421b1693b1ab33225c.tar.gz astro-06eff60cabb55d91fe4075421b1693b1ab33225c.tar.zst astro-06eff60cabb55d91fe4075421b1693b1ab33225c.zip |
Add copy support for Wayland via wl-copy (#11964)
* Add wl-copy support
* Add changeset
* set to patch
---------
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
-rw-r--r-- | .changeset/two-suns-admire.md | 5 | ||||
-rw-r--r-- | packages/astro/src/cli/info/index.ts | 34 |
2 files changed, 27 insertions, 12 deletions
diff --git a/.changeset/two-suns-admire.md b/.changeset/two-suns-admire.md new file mode 100644 index 000000000..36fb5f5ba --- /dev/null +++ b/.changeset/two-suns-admire.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Add wayland (wl-copy) support to `astro info` diff --git a/packages/astro/src/cli/info/index.ts b/packages/astro/src/cli/info/index.ts index 3fa91802f..3bb2216c0 100644 --- a/packages/astro/src/cli/info/index.ts +++ b/packages/astro/src/cli/info/index.ts @@ -55,6 +55,7 @@ export async function printInfo({ flags }: InfoOptions) { } async function copyToClipboard(text: string) { + text = text.trim() const system = platform(); let command = ''; if (system === 'darwin') { @@ -62,18 +63,26 @@ async function copyToClipboard(text: string) { } else if (system === 'win32') { command = 'clip'; } else { - try { - // Unix: check if `xclip` is installed - const output = execSync('which xclip', { encoding: 'utf8' }); - if (output[0] !== '/') { - // Did not find a path for xclip, bail out! - return; + // Unix: check if a supported command is installed + const unixCommands = [ + ['xclip', '-sel clipboard -l 1'], + ['wl-copy', '"$0"'] + ] + for (const [unixCommand, args] of unixCommands) { + try { + const output = execSync(`which ${unixCommand}`, { encoding: 'utf8', stdio: 'pipe' }); + if (output[0] !== '/') { + // Did not find a path. Skip! + continue; + } + command = `${unixCommand} ${args}`; + } catch { + // Failed to execute which. Skip! + continue; } - command = 'xclip -sel clipboard -l 1'; - } catch { - // Did not find xclip, bail out! - return; } + // Did not find supported command. Bail out! + if (!command) return; } console.log(); @@ -86,8 +95,9 @@ async function copyToClipboard(text: string) { if (!shouldCopy) return; try { - execSync(command, { - input: text.trim(), + execSync(command.replaceAll('$0', text), { + stdio: 'ignore', + input: text, encoding: 'utf8', }); } catch { |