diff --git a/src/util/clipboard-util.ts b/src/util/clipboard-util.ts index 8bbf30b..7f87ad7 100644 --- a/src/util/clipboard-util.ts +++ b/src/util/clipboard-util.ts @@ -1,7 +1,16 @@ import { spawn } from 'child_process'; +import { getCopyToClipboardCommandArgs } from './config-util'; + +const clipboardCommandArgs = getCopyToClipboardCommandArgs(); export const writeToClipboard = async (text: string): Promise => { - 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); @@ -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));