Skip to content

Commit

Permalink
fix: Astro info throws when xclip is not available (#9042)
Browse files Browse the repository at this point in the history
* Update index.ts

* Create hot-teachers-wave.md

* Update .changeset/hot-teachers-wave.md

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>

---------

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
  • Loading branch information
2 people authored and natemoo-re committed Nov 22, 2023
1 parent 79af662 commit e734603
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-teachers-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Safely bail when the `xclip` command does not exist on Linux when trying to copy to clipboard with `astro info`
18 changes: 12 additions & 6 deletions packages/astro/src/cli/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ async function copyToClipboard(text: string) {
} else if (system === 'win32') {
command = 'clip';
} else {
// 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;
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;
}
command = 'xclip -sel clipboard -l 1';
}
catch (e) {
// Did not find xclip, bail out!
return
}
command = 'xclip -sel clipboard -l 1';
}

console.log();
Expand Down

0 comments on commit e734603

Please sign in to comment.