Skip to content

Commit 419b198

Browse files
author
Pete Bishop
committed
Output to Clipboard support
1 parent 3058bbc commit 419b198

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Commands/DebugCommand.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public function handle(): void
3737
case 'File':
3838
$this->outputToFile();
3939
break;
40+
case 'Clipboard':
41+
$this->outputToClipboard();
42+
break;
4043
case 'Console':
4144
$this->outputToConsole();
4245
break;
@@ -156,7 +159,7 @@ protected function promptForMissingArgumentsUsing(): array
156159
return [
157160
'output' => fn () => select(
158161
'Where would you like to output the debug information?',
159-
['File', 'Console'],
162+
['File', 'Clipboard', 'Console'],
160163
'File'
161164
),
162165
];
@@ -174,4 +177,18 @@ private function outputToConsole(): void
174177
print_r($this->debugInfo->toArray(), true)
175178
);
176179
}
180+
181+
private function outputToClipboard(): void
182+
{
183+
$json = json_encode($this->debugInfo->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
184+
185+
// Copy json to clipboard
186+
if (PHP_OS_FAMILY === 'Windows') {
187+
Process::run('echo ' . escapeshellarg($json) . ' | clip');
188+
} elseif (PHP_OS_FAMILY === 'Linux') {
189+
Process::run('echo ' . escapeshellarg($json) . ' | xclip -selection clipboard');
190+
} else {
191+
Process::run('echo ' . escapeshellarg($json) . ' | pbcopy');
192+
}
193+
}
177194
}

0 commit comments

Comments
 (0)