- const indent = i > 0 ? ' ' : '';
- // Escape newlines on every non-last arg when there are multiple lines
- const lineBreak = arr.length > 1 && i < arr.length - 1 ? ' \\' : '';
- arr[i] = `${indent}${item}${lineBreak}`;
- });
+ const indent = index > 0 ? ' ' : '';
+ // Add backslash "escaped linebreak"
+ const lineBreak = lines.length > 1 && index < lines.length - 1 ? ' \\' : '';
+
+ return `${indent}${line}${lineBreak}`;
+ };
+
+ const formatClipboardText = (command: string[]) => (): string => (
+ command.map((v) =>
+ shellescape([v]) // Escape each arg separately
+ ).join(' ')
+ );