496
497
export function sanitizeFishHistoryCmd(cmd: string): string {
499
>
* NOTE
500
>
* This repeatedReplace() call can be eliminated by using look-ahead
501
>
* caluses in the original RegExp pattern:
502
>
*
503
>
* >>> ```ts
504
>
* >>> cmds[i].replace(/(?<=^|[^\\])((?:\\\\)*)(\\n)/g, '$1\n')
505
>
* >>> ```
506
>
*
507
>
* But since not all browsers support look aheads we opted to a simple
508
>
* pattern and repeatedly calling replace method.
509
>
*/
510
>
return repeatedReplace(/(^|[^\\])((?:\\\\)*)(\\n)/g, cmd, '$1$2\n');
511
>
}
512
513
>
function repeatedReplace(pattern: RegExp, value: string, replaceValue: string): string {
history.ts
514
>
let last;
515
>
let current = value;
516
>
while (true) {
517
>
last = current;
518
>
current = current.replace(pattern, replaceValue);
519
>
if (current === last) {
520
>
return current;
521
>
}
522
>
}
523
>
}
524
525
async function fetchFileContents(