mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-24 08:45:18 +01:00
Merge pull request #197099 from hamirmahal/feat/allow-keyboard-shortcut-creation-for-terminal-copy-commands
feat: allow keyboard shortcut creation for terminal copy commands
This commit is contained in:
@@ -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);
|
||||
@@ -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...' },
|
||||
|
||||
@@ -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',
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user