-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Description
Refs: #133084
- macOS @rzhao271 - pwsh, bash
- linux @roblourens - zsh
- windows @connor4312 - pwsh
Complexity: 5
Authors: @Tyriar, @meganrogge
The terminal now features "shell integration" with the opt-in setting terminal.integrated.enableShellIntegration. The basics of this feature is that it runs a script in your shell of choice and injects invisible sequences at key points to tell the terminal about certain things, like where the prompt, command, output starts and what the current working directory (cwd) is. Shell integration activates by injecting arguments into the profile while it is starting up, you can view these injected arguments by looking for terminalInstance#ctor in a trace log.
Since a shell script needs to be written on a shell-by-shell basis, only the following are currently supported:
- Windows
- pwsh (6+, not "Windows PowerShell")
- Linux/macOS
- pwsh
- bash
- zsh
Currently these new insights into what's happening within the shell are used in the following features:
- New command:
Run Recent Command, running this after a terminal command executed is the easiest way to tell if shell integration is working- This command has a button on the right to open the command's output in the editor
- New command:
Terminal: Go to Recent Directory - Current working directory detection on Windows (this only worked on non-Windows before), this drives the following:
- The
terminal.integrated.splitCwdsetting - Links in the terminal are resolved relatively against the current working directory
- The
- Clicking links in the terminal now resolve the links relatively to whatever cwd the command they're contained within. For example if you
cdinto a new directory, any links clicked below that will resolve against the new directory and any above that will use the old directory. - The old commands
Select/Scroll to Previous/Next Commandnow use shell integration if it's available, otherwise they fallback to the old mechanism (which assumed it was a command anytime you press enter when the cursor was in the 3rd column or beyond)
Test the feature on each of the shells assigned to your platform. Some things to try:
- Does shell integration activate?
- Install a special prompt and see if shell integration still works, if not does it fail gracefully?
- Test the new features above
- Does the hover for your terminal tab show information about shell integration?
- Turn off shell integration and try the features, do they work as expected?
Here are some of the main limitations you may hit while testing:
$PS2isn't supported on bash and zsh yet (line continuations should work on Windows) Support sequence for PS2 for commands containing line breaks #140665- Right prompts aren't supported yet Shell integration: Ensure command detection works with right prompts #140928