243
return undefined;
244
}
245
>
const sourceLabel = '~/.bash_history';
history.ts
246
const home = remoteEnvironment?.userHome?.fsPath ?? env['HOME'];
247
const resolvedFile = await fetchFileContents(home, '.bash_history', false, fileService, remoteAgentService);
248
>
if (resolvedFile === undefined) {
history.ts
249
return undefined;
250
}
251
>
// .bash_history does not differentiate wrapped commands from multiple commands. Parse
history.ts
252
>
// the output to get the
253
>
const fileLines = resolvedFile.content.split('\n');
254
>
const result: Set<string> = new Set();
255
>
let currentLine: string;
256
>
let currentCommand: string | undefined = undefined;
257
>
let wrapChar: string | undefined = undefined;
258
>
for (let i = 0; i < fileLines.length; i++) {
259
>
currentLine = fileLines[i];
260
>
if (currentCommand === undefined) {
261
>
currentCommand = currentLine;
262
>
} else {
263
>
currentCommand += `\n${currentLine}`;
264
>
}
265
>
for (let c = 0; c < currentLine.length; c++) {
266
>
if (wrapChar) {
267
>
if (currentLine[c] === wrapChar) {
268
>
wrapChar = undefined;
269
>
}
270
>
} else {
271
>
if (currentLine[c].match(/['"]/)) {
272
>
wrapChar = currentLine[c];
273
>
}
274
>
}
275
>
}
276
>
if (wrapChar === undefined) {
277
>
if (currentCommand.length > 0) {
278
>
result.add(currentCommand.trim());
279
>
}
280
>
currentCommand = undefined;
281
>
}
282
>
}
283
>
284
>
return {
285
>
sourceLabel,
286
>
sourceResource: resolvedFile.resource,
287
>
commands: Array.from(result.values())
288
>
};
289
>
}
290
291
export async function fetchZshHistory(accessor: ServicesAccessor): Promise<IShellFileHistoryEntry | undefined> {