(filePath: string)
| 28 | |
| 29 | // Handle multiline commands |
| 30 | async function readHistoryFile(filePath: string): Promise<string[]> { |
| 31 | try { |
| 32 | const text = await fs.readFile(filePath, 'utf-8'); |
| 33 | const result: string[] = []; |
| 34 | let cur = ''; |
| 35 | |
| 36 | for (const raw of text.split(/\r?\n/)) { |
| 37 | if (!raw.trim()) continue; |
| 38 | const line = raw; |
| 39 | |
| 40 | const m = cur.match(/(\\+)$/); |
| 41 | if (m && m[1].length % 2) { |
| 42 | // odd number of trailing '\' |
| 43 | cur = cur.slice(0, -1) + ' ' + line; |
| 44 | } else { |
| 45 | if (cur) result.push(cur); |
| 46 | cur = line; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | if (cur) result.push(cur); |
| 51 | return result; |
| 52 | } catch (err) { |
| 53 | if (isNodeError(err) && err.code === 'ENOENT') return []; |
| 54 | console.error('Error reading history:', err); |
| 55 | return []; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | async function writeHistoryFile( |
| 60 | filePath: string, |
no test coverage detected