src/vs/workbench/contrib/terminal/browser/terminalInstance.ts/TerminalInstance/runRecent
class TerminalInstance:	async runRecent(type: 'command' | 'cwd'): Promise<void> {
		if (!this.xterm) {
			return;
		}
		type Item = IQuickPickItem & { command?: ITerminalCommand };
		let items: (Item | IQuickPickItem | IQuickPickSeparator)[] = [];
		const commandMap: Set<string> = new Set();

		const removeFromCommandHistoryButton: IQuickInputButton = {
			iconClass: ThemeIcon.asClassName(Codicon.close),
			tooltip: nls.localize('removeCommand', "Remove from Command History")
		};

		if (type === 'command') {
			const cmdDetection = this.capabilities.get(TerminalCapability.CommandDetection);
			const commands = cmdDetection?.commands;
			// Current session history
			const executingCommand = cmdDetection?.executingCommand;
			if (executingCommand) {
				commandMap.add(executingCommand);
			}
			if (commands && commands.length > 0) {
				for (const entry of commands) {
					// trim off any whitespace and/or line endings
					const label = entry.command.trim();
					if (label.length === 0 || commandMap.has(label)) {
						continue;
					}
					let description = `${entry.cwd}`;
					if (entry.exitCode) {
						// Since you cannot get the last command's exit code on pwsh, just whether it failed
						// or not, -1 is treated specially as simply failed
						if (entry.exitCode === -1) {
							description += ' failed';
						} else {
							description += ` exitCode: ${entry.exitCode}`;
						}
					}
					description = description.trim();
					const iconClass = ThemeIcon.asClassName(Codicon.output);
					const buttons: IQuickInputButton[] = [{
						iconClass,
						tooltip: nls.localize('viewCommandOutput', "View Command Output"),
						alwaysVisible: false
					}];
					// Merge consecutive commands
					const lastItem = items.length > 0 ? items[items.length - 1] : undefined;
					if (lastItem?.type !== 'separator' && lastItem?.label === label) {
						lastItem.id = entry.timestamp.toString();
						lastItem.description = description;
						continue;
					}
					items.push({
						label,
						description,
						id: entry.timestamp.toString(),
						command: entry,
						buttons: entry.hasOutput ? buttons : undefined
					});
					commandMap.add(label);
				}
				items = items.reverse();
			}
			if (executingCommand) {
				items.unshift({
					label: executingCommand,
					description: cmdDetection.cwd
				});
			}
			if (items.length > 0) {
				items.unshift({ type: 'separator', label: terminalStrings.currentSessionCategory });
			}

			// Gather previous session history
			const history = this._instantiationService.invokeFunction(getCommandHistory);
			const previousSessionItems: IQuickPickItem[] = [];
			for (const [label, info] of history.entries) {
				// Only add previous session item if it's not in this session
				if (!commandMap.has(label) && info.shellType === this.shellType) {
					previousSessionItems.unshift({
						label,
						buttons: [removeFromCommandHistoryButton]
					});
				}
			}
			if (previousSessionItems.length > 0) {
				items.push(
					{ type: 'separator', label: terminalStrings.previousSessionCategory },
					...previousSessionItems
				);
			}
		} else {
			const cwds = this.capabilities.get(TerminalCapability.CwdDetection)?.cwds || [];
			if (cwds && cwds.length > 0) {
				for (const label of cwds) {
					items.push({ label });
				}
				items = items.reverse();
				items.unshift({ type: 'separator', label: terminalStrings.currentSessionCategory });
			}

			// Gather previous session history
			const history = this._instantiationService.invokeFunction(getDirectoryHistory);
			const previousSessionItems: IQuickPickItem[] = [];
			// Only add previous session item if it's not in this session and it matches the remote authority
			for (const [label, info] of history.entries) {
				if ((info === null || info.remoteAuthority === this.remoteAuthority) && !cwds.includes(label)) {
					previousSessionItems.unshift({
						label,
						buttons: [removeFromCommandHistoryButton]
					});
				}
			}
			if (previousSessionItems.length > 0) {
				items.push(
					{ type: 'separator', label: terminalStrings.previousSessionCategory },
					...previousSessionItems
				);
			}
		}
		if (items.length === 0) {
			return;
		}
		const outputProvider = this._instantiationService.createInstance(TerminalOutputProvider);
		const quickPick = this._quickInputService.createQuickPick();
		quickPick.items = items;
		return new Promise<void>(r => {
			quickPick.onDidTriggerItemButton(async e => {
				if (e.button === removeFromCommandHistoryButton) {
					if (type === 'command') {
						this._instantiationService.invokeFunction(getCommandHistory)?.remove(e.item.label);
					} else {
						this._instantiationService.invokeFunction(getDirectoryHistory)?.remove(e.item.label);
					}
				} else {
					const selectedCommand = (e.item as Item).command;
					const output = selectedCommand?.getOutput();
					if (output && selectedCommand?.command) {
						const textContent = await outputProvider.provideTextContent(URI.from(
							{
								scheme: TerminalOutputProvider.scheme,
								path: `${selectedCommand.command}... ${fromNow(selectedCommand.timestamp, true)}`,
								fragment: output,
								query: `terminal-output-${selectedCommand.timestamp}-${this.instanceId}`
							}));
						if (textContent) {
							await this._editorService.openEditor({
								resource: textContent.uri
							});
						}
					}
				}
				quickPick.hide();
			});
			quickPick.onDidAccept(e => {
				const result = quickPick.activeItems[0];
				this.sendText(type === 'cwd' ? `cd ${result.label}` : result.label, true);
				quickPick.hide();
			});
			quickPick.show();
			quickPick.onDidHide(() => r());
		});
	}