Skip to content

Commit

Permalink
clipboard-util.ts: attempts to use the configured clipboard command i…
Browse files Browse the repository at this point in the history
…f one is found
  • Loading branch information
drewbrokke committed Oct 27, 2020
1 parent 8f37b8c commit 8eb82de
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/util/clipboard-util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { spawn } from 'child_process';
import { getCopyToClipboardCommandArgs } from './config-util';

const clipboardCommandArgs = getCopyToClipboardCommandArgs();

export const writeToClipboard = async (text: string): Promise<void> => {
if (process.platform === 'darwin') {
if (clipboardCommandArgs.length) {
return await doWriteToClipboard(
clipboardCommandArgs[0],
clipboardCommandArgs.slice(1),
text,
);
} else if (process.platform === 'darwin') {
return await doWriteToClipboard('pbcopy', [], text);
} else {
return await doWriteToClipboard('xsel', ['--input'], text);
Expand All @@ -16,6 +25,13 @@ const doWriteToClipboard = async (
return new Promise((resolve, reject) => {
const copyProcess = spawn(command, args);

copyProcess.on('error', (error: Error) => {
return reject(
new Error(`There was a problem running process: ${command}
${error.message}`),
);
});

let errorString = '';

copyProcess.stderr.on('data', (data: string) => (errorString += data));
Expand Down

0 comments on commit 8eb82de

Please sign in to comment.