import { Disposable , ExtensionContext , Terminal , window } from 'vscode' ; import { getExtensionContext } from './extensionContext' ; const terminalName = 'gitops' ; let _terminal ; let _currentDirectory ; let _disposable ; param context param workingDirectory returns function getTerminal ( context , workingDirectory ? ) { if ( _terminal === undefined ) { _terminal = window . createTerminal ( terminalName ) ; _disposable = window . onDidCloseTerminal ( ( e ) => { if ( e . name === terminalName ) { _terminal = undefined ; _disposable ?. dispose ( ) ; _disposable = undefined ; } } ) ; context . subscriptions . push ( _disposable ) ; _currentDirectory = undefined ; } if ( _currentDirectory !== workingDirectory && workingDirectory && workingDirectory . length > 0 ) { _terminal . sendText ( `cd "${ workingDirectory }"` , true ) ; _currentDirectory = workingDirectory ; } return _terminal ; } param command param cwd param focusTerminal export function runTerminalCommand ( command , { cwd , focusTerminal , } = { } ) { const terminal = getTerminal ( getExtensionContext ( ) , cwd ) ; terminal . show ( ! focusTerminal ) ; terminal . sendText ( command , true ) ; }