mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
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>
This commit is contained in:
parent
490eed1cd9
commit
06eff60cab
2 changed files with 27 additions and 12 deletions
5
.changeset/two-suns-admire.md
Normal file
5
.changeset/two-suns-admire.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add wayland (wl-copy) support to `astro info`
|
|
@ -55,6 +55,7 @@ export async function printInfo({ flags }: InfoOptions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copyToClipboard(text: string) {
|
async function copyToClipboard(text: string) {
|
||||||
|
text = text.trim()
|
||||||
const system = platform();
|
const system = platform();
|
||||||
let command = '';
|
let command = '';
|
||||||
if (system === 'darwin') {
|
if (system === 'darwin') {
|
||||||
|
@ -62,19 +63,27 @@ async function copyToClipboard(text: string) {
|
||||||
} else if (system === 'win32') {
|
} else if (system === 'win32') {
|
||||||
command = 'clip';
|
command = 'clip';
|
||||||
} else {
|
} else {
|
||||||
|
// 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 {
|
try {
|
||||||
// Unix: check if `xclip` is installed
|
const output = execSync(`which ${unixCommand}`, { encoding: 'utf8', stdio: 'pipe' });
|
||||||
const output = execSync('which xclip', { encoding: 'utf8' });
|
|
||||||
if (output[0] !== '/') {
|
if (output[0] !== '/') {
|
||||||
// Did not find a path for xclip, bail out!
|
// Did not find a path. Skip!
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
command = 'xclip -sel clipboard -l 1';
|
command = `${unixCommand} ${args}`;
|
||||||
} catch {
|
} catch {
|
||||||
// Did not find xclip, bail out!
|
// Failed to execute which. Skip!
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Did not find supported command. Bail out!
|
||||||
|
if (!command) return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log();
|
console.log();
|
||||||
const { shouldCopy } = await prompts({
|
const { shouldCopy } = await prompts({
|
||||||
|
@ -86,8 +95,9 @@ async function copyToClipboard(text: string) {
|
||||||
if (!shouldCopy) return;
|
if (!shouldCopy) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execSync(command, {
|
execSync(command.replaceAll('$0', text), {
|
||||||
input: text.trim(),
|
stdio: 'ignore',
|
||||||
|
input: text,
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
|
|
Loading…
Reference in a new issue