From 46c609b40a7973eaa6f36668cfdf3aa98687ad65 Mon Sep 17 00:00:00 2001 From: Reuben Tier Date: Tue, 10 Sep 2024 15:27:08 +0100 Subject: [PATCH 1/3] Add wl-copy support --- packages/astro/src/cli/info/index.ts | 34 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/astro/src/cli/info/index.ts b/packages/astro/src/cli/info/index.ts index 3fa91802f26e..3bb2216c0c94 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 { From 1bfd6f08e3bf26a1c881036cfaebcb8949ab9bdf Mon Sep 17 00:00:00 2001 From: Reuben Tier Date: Tue, 10 Sep 2024 15:31:35 +0100 Subject: [PATCH 2/3] Add changeset --- .changeset/two-suns-admire.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/two-suns-admire.md diff --git a/.changeset/two-suns-admire.md b/.changeset/two-suns-admire.md new file mode 100644 index 000000000000..093a1efd0844 --- /dev/null +++ b/.changeset/two-suns-admire.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Add wayland (wl-copy) support to `astro info` From 1dee0c7fa65557034a4df88b7284335c075abf29 Mon Sep 17 00:00:00 2001 From: Reuben Tier Date: Tue, 10 Sep 2024 18:32:32 +0100 Subject: [PATCH 3/3] set to patch --- .changeset/two-suns-admire.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/two-suns-admire.md b/.changeset/two-suns-admire.md index 093a1efd0844..36fb5f5ba39c 100644 --- a/.changeset/two-suns-admire.md +++ b/.changeset/two-suns-admire.md @@ -1,5 +1,5 @@ --- -'astro': minor +'astro': patch --- Add wayland (wl-copy) support to `astro info`