1

I'd find it convenient to be able to quickly recall past commands issued in the terminal. In Matlab one can simply select any number of those from the Command HIstory panel, and reissue them in the Terminal all at once:

enter image description here

In VS Code (on Windows), I know there is a command to pull up the log text file:

(Get-PSReadlineOption).HistorySavePath

But I find this extremely cumbersome as a solution to call up multiple lines at a time. Is there an VS Code addon that creates a Matlab-like Command History panel with timestamped commands (didn't find any searching myself)? Or is such feedback taken into consideration by Microsoft?

z8080
  • 571
  • 3
  • 7
  • 23
  • Please don't tag Visual Studio for a Visual Studio Code question – phuzi Jan 04 '22 at 11:43
  • The terminal in VS Code is (usually) Powershell. Perhaps you should be looking for a Powershell solution?! – phuzi Jan 04 '22 at 11:46
  • Or perhaps if you have a common set of commands you run, did you consider writing a Powershell script? – phuzi Jan 04 '22 at 11:47
  • @phuzi sorry - fixed – z8080 Jan 04 '22 at 12:47
  • I'm not sure what to do about Powershell, I am not an advanced user and was simply wondering how to have a Command History panel. Since there's no addon for it, filing a feedback ticket with MS seems the way to go – z8080 Jan 04 '22 at 12:48

1 Answers1

2

See v1.70 release notes:

Triggering the Terminal: Run Recent Command... will bring up a QuickPick panel of recent terminal commands in which you can search, fuzzy or not, through the recent commands.

There are some examples of commands for going to the next item in the list, for example.

See the supported shells and OS's mentioned below. I believe it is still accurate. Git Bash on Windows doesn't work with this new recent command functionality, but powershell does. Support for MacOS and linux is stronger: bash, powershell and zsh.

And see v1.69 release notes: run recent command:

Some other functionality of the command:

In the current session section, there is a clipboard icon in the right of the Quick Pick that will open the command output in an editor. Alt can be held to write the text to the terminal without running it. The amount of history stored in the previous session section is determined by the terminal.integrated.shellIntegration.history setting.

There is currently no keybinding assigned by default but it can be hooked up to Ctrl+Space for example with the following keybinding:

{
    "key": "ctrl+space",    // whatever keybinding you want
    "command": "workbench.action.terminal.runRecentCommand",
    "when": "terminalFocus"
}

This might help (coming to v1.64):

Terminal shell integration

The terminal now features experimental opt-in shell integration which allows VS Code to gain insights on what is going on within the terminal as it was previously a black box. When enabled using "terminal.integrated.enableShellIntegration": true, arguments to run a shell integration script will be injected into your terminal profile if possible. The script itself mostly just injects invisible sequences into your prompt, providing us with information like where the prompt, command and command output is, what the current working directory (cwd) is for each command and the exit code of each command.

Shell integration enables the following new features:

Run recent command: Since we know what commands are run, we have exposed a command that allows you to view and run them again in a quick pick.

Developer: Run Recent Command run this command from the Command Palette

run recent command image

The current shells supported are pwsh for Windows and pwsh, bash and zsh for Linux and macOS.

Although I switched to powerShell on W11 to test this feature - which should be supported - I can't get it to work just now. I wanted to see if you could pick multiple command entries in the QuickPick to run a series of them, but I doubt you can. But at least you get a nice list of recent commands.

Mark
  • 143,421
  • 24
  • 428
  • 436