@@ -433,9 +433,27 @@ export function registerTerminalActions() {
433433 }
434434 } ) ;
435435
436+ registerActiveInstanceAction ( {
437+ id : TerminalCommandId . CopyLastCommand ,
438+ title : { value : localize ( 'workbench.action.terminal.copyLastCommand' , 'Copy Last Command' ) , original : 'Copy Last Command' } ,
439+ precondition : ContextKeyExpr . or ( TerminalContextKeys . processSupported , TerminalContextKeys . terminalHasBeenCreated ) ,
440+ run : async ( instance , c , accessor ) => {
441+ const clipboardService = accessor . get ( IClipboardService ) ;
442+ const commands = instance . capabilities . get ( TerminalCapability . CommandDetection ) ?. commands ;
443+ if ( ! commands || commands . length === 0 ) {
444+ return ;
445+ }
446+ const command = commands [ commands . length - 1 ] ;
447+ if ( ! command . command ) {
448+ return ;
449+ }
450+ await clipboardService . writeText ( command . command ) ;
451+ }
452+ } ) ;
453+
436454 registerActiveInstanceAction ( {
437455 id : TerminalCommandId . CopyLastCommandOutput ,
438- title : { value : localize ( 'workbench.action.terminal.copyLastCommand ' , 'Copy Last Command Output' ) , original : 'Copy Last Command Output' } ,
456+ title : { value : localize ( 'workbench.action.terminal.copyLastCommandOutput ' , 'Copy Last Command Output' ) , original : 'Copy Last Command Output' } ,
439457 precondition : ContextKeyExpr . or ( TerminalContextKeys . processSupported , TerminalContextKeys . terminalHasBeenCreated ) ,
440458 run : async ( instance , c , accessor ) => {
441459 const clipboardService = accessor . get ( IClipboardService ) ;
@@ -454,6 +472,28 @@ export function registerTerminalActions() {
454472 }
455473 } ) ;
456474
475+ registerActiveInstanceAction ( {
476+ id : TerminalCommandId . CopyLastCommandAndLastCommandOutput ,
477+ title : { value : localize ( 'workbench.action.terminal.copyLastCommandAndOutput' , 'Copy Last Command and Output' ) , original : 'Copy Last Command and Output' } ,
478+ precondition : ContextKeyExpr . or ( TerminalContextKeys . processSupported , TerminalContextKeys . terminalHasBeenCreated ) ,
479+ run : async ( instance , c , accessor ) => {
480+ const clipboardService = accessor . get ( IClipboardService ) ;
481+ const commands = instance . capabilities . get ( TerminalCapability . CommandDetection ) ?. commands ;
482+ if ( ! commands || commands . length === 0 ) {
483+ return ;
484+ }
485+ const command = commands [ commands . length - 1 ] ;
486+ if ( ! command ?. hasOutput ( ) ) {
487+ return ;
488+ }
489+ const output = command . getOutput ( ) ;
490+ if ( isString ( output ) ) {
491+ await clipboardService . writeText ( `${ command . command !== '' ? command . command + '\n' : '' } ${ output } ` ) ;
492+ }
493+ }
494+ } ) ;
495+
496+
457497 registerActiveInstanceAction ( {
458498 id : TerminalCommandId . GoToRecentDirectory ,
459499 title : { value : localize ( 'workbench.action.terminal.goToRecentDirectory' , "Go to Recent Directory..." ) , original : 'Go to Recent Directory...' } ,
0 commit comments