Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,27 @@ export function registerTerminalActions() {
}
});

registerActiveInstanceAction({
id: TerminalCommandId.CopyLastCommand,
title: { value: localize('workbench.action.terminal.copyLastCommand', 'Copy Last Command'), original: 'Copy Last Command' },
precondition: ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
run: async (instance, c, accessor) => {
const clipboardService = accessor.get(IClipboardService);
const commands = instance.capabilities.get(TerminalCapability.CommandDetection)?.commands;
if (!commands || commands.length === 0) {
return;
}
const command = commands[commands.length - 1];
if (!command.command) {
return;
}
await clipboardService.writeText(command.command);
}
});

registerActiveInstanceAction({
id: TerminalCommandId.CopyLastCommandOutput,
title: { value: localize('workbench.action.terminal.copyLastCommand', 'Copy Last Command Output'), original: 'Copy Last Command Output' },
title: { value: localize('workbench.action.terminal.copyLastCommandOutput', 'Copy Last Command Output'), original: 'Copy Last Command Output' },
precondition: ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
run: async (instance, c, accessor) => {
const clipboardService = accessor.get(IClipboardService);
Expand All @@ -454,6 +472,28 @@ export function registerTerminalActions() {
}
});

registerActiveInstanceAction({
id: TerminalCommandId.CopyLastCommandAndLastCommandOutput,
title: { value: localize('workbench.action.terminal.copyLastCommandAndOutput', 'Copy Last Command and Output'), original: 'Copy Last Command and Output' },
precondition: ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
run: async (instance, c, accessor) => {
const clipboardService = accessor.get(IClipboardService);
const commands = instance.capabilities.get(TerminalCapability.CommandDetection)?.commands;
if (!commands || commands.length === 0) {
return;
}
const command = commands[commands.length - 1];
if (!command?.hasOutput()) {
return;
}
const output = command.getOutput();
if (isString(output)) {
await clipboardService.writeText(`${command.command !== '' ? command.command + '\n' : ''}${output}`);
}
}
});


registerActiveInstanceAction({
id: TerminalCommandId.GoToRecentDirectory,
title: { value: localize('workbench.action.terminal.goToRecentDirectory', "Go to Recent Directory..."), original: 'Go to Recent Directory...' },
Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ export const enum TerminalCommandId {
FocusAccessibleBuffer = 'workbench.action.terminal.focusAccessibleBuffer',
AccessibleBufferGoToNextCommand = 'workbench.action.terminal.accessibleBufferGoToNextCommand',
AccessibleBufferGoToPreviousCommand = 'workbench.action.terminal.accessibleBufferGoToPreviousCommand',
CopyLastCommand = 'workbench.action.terminal.copyLastCommand',
CopyLastCommandOutput = 'workbench.action.terminal.copyLastCommandOutput',
CopyLastCommandAndLastCommandOutput = 'workbench.action.terminal.copyLastCommandAndLastCommandOutput',
GoToRecentDirectory = 'workbench.action.terminal.goToRecentDirectory',
CopyAndClearSelection = 'workbench.action.terminal.copyAndClearSelection',
CopySelection = 'workbench.action.terminal.copySelection',
Expand Down Expand Up @@ -513,7 +515,9 @@ export const DEFAULT_COMMANDS_TO_SKIP_SHELL: string[] = [
TerminalCommandId.CopyAndClearSelection,
TerminalCommandId.CopySelection,
TerminalCommandId.CopySelectionAsHtml,
TerminalCommandId.CopyLastCommand,
TerminalCommandId.CopyLastCommandOutput,
TerminalCommandId.CopyLastCommandAndLastCommandOutput,
TerminalCommandId.DeleteToLineStart,
TerminalCommandId.DeleteWordLeft,
TerminalCommandId.DeleteWordRight,
Expand Down