Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement terminal shell integration #133084

Closed
Tyriar opened this issue Sep 14, 2021 · 1 comment
Closed

Implement terminal shell integration #133084

Tyriar opened this issue Sep 14, 2021 · 1 comment
Assignees
Labels
feature-request Request for new features or functionality on-release-notes Issue/pull request mentioned in release notes on-testplan terminal Integrated terminal issues
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Sep 14, 2021

Shell integration involves injecting sequences into the prompt such that we know additional information about what is happening in the process such as:

  • The start of the prompt
  • The end of the prompt/start of the input
  • The end of the input
  • The current working directory
  • The exit code of last process/command

This additional information enables a lot of possibilities:

  • A more reliable and faster mechanism for detecting the cwd - one that actually works on Windows (at least for pwsh). For Windows this would allow lighting up some functionality that's currently disabled like inheriting the cwd in split terminals or resolving links relative to the cwd.
  • Track command prompts, inputs and their output. This enables things like tracking command history, separating "execution blocks", collapsing past output, block-level actions/context menu, etc.
  • Potentially exposing a run command extension API which runs within an existing shell session and returns the exit code, additional state could also be exposed via Terminal.state.
  • Overall better awareness of what's going on inside the terminal, currently it's mostly a black box and the main ways of detecting things is via scanning all text (eg. tasks) or by listening for certain key presses (eg. current command tracking).
  • If we know reliably when input is being accepted into the shell and what the current input is, we could provide auto-complete of history - this could even be extended to extensions in a similar way that the text area does it. Taking this a step further, monaco could potentially be used which enabled multi-cursor, familiar shortcuts, etc. (that would lose native shell autocomplete though).

Notes:

@Tyriar Tyriar added feature-request Request for new features or functionality terminal Integrated terminal issues labels Sep 14, 2021
@Tyriar Tyriar added this to the On Deck milestone Sep 14, 2021
@Tyriar Tyriar modified the milestones: On Deck, December 2021 Dec 6, 2021
@Tyriar
Copy link
Member Author

Tyriar commented Dec 17, 2021

I break down high level goals and tasks below, with a bunch of notes that might be useful when working on the issues.

Goals:

  • Allow users to opt-in to shell integration terminals for supported shells which enhances their terminal experience
  • Shell integration should enhance make certain existing terminal features more robust (eg. command tracking, relative links, etc.)
  • New features should light up when shell integration is enabled (eg. Command history, cwd history, accessibility improvements)

Task breakdown

Raw notes:

- Task: Explore how we're going to enable shell integration for each shell
- Supported shells: Pwsh, bash and zsh (fish if time allows)
	○ Task: Write pwsh shell integration script
	○ Task: Write bash shell integration script
	○ Task: Write zsh shell integration script
- Have an auto detected profile that allows running the default shell with shell integration (if it's detected as possible)
- Docs on the website on how shell integration is enabled
- We should handle shell integration enabled inner shells gracefully (eg. run bash in bash)
- Task: Surface shell integration/capabilities in the terminal tab hover
- Task: Handle partial support on Windows, initial explorations showed conpty messed up the shell integration sequences as they're output by the renderer not the parser. This means some capabilities may not work 100% on Windows.
- Shell integration should conditionally light up the following new capabilities:
	○ Command tracking
		§ Command tracking exists but its guessing on what lines commands are run, when this capability is enabled for the terminal the old mechanism (xterm addon) would be disabled and replaced by the new mechanism
		§ Task: Rename CommandTrackerAddon to NaiveCommandTrackerAddon https://github.com/Microsoft/vscode/blob/8cd6ff6d7301fc66c119c44f4e031db76cfe87be/src/vs/workbench/contrib/terminal/browser/xterm/commandTrackerAddon.ts#L24
		§ The old and new command tracker commands should share similar interfaces to reduce code duplication
	○ Cwd tracking
		§ Currently cwd tracking is done on macOS and Linux by running lsof or checking procos respectively, these mechanism can be disabled if we get the cwd from shell integration as it will come in faster and without the need for additional polling
- The following features will be added based on active capabilities:
	○ Command history command (dep: Command tracking)
		§ This will present a quick pick with all recently run terminal commands, including command name, cwd, exit code
		§ When selected in the quick pick, the command will run in the active terminal
		§ Should have smoke tests
		§ Whatever tracks command history should have unit tests
		§ Considerations:
			□ Do we have a maximum of entries we track?
			□ Should this be sorted by recency of frequency?
			□ Can we avoid settings for this feature?
	○ Syncing of textarea for screen readers (dep: Command tracking)
		§ Currently we clear the invisible text area in xterm.js when we're unsure what the prompt's state is, with real command tracking we will be able to synchronize the textarea with the prompt and cursor to get left/right/backspace/delete correctly announcing the textual changes to screen reader users
		§ Considerations:
			□ This might need to be a new API in xterm.js so it avoids clearing the textarea
	○ Better cwd detection (dep: Cwd tracking)
		§ This will replace the naïve cwd detection approach when it's available and enable relative link and splitCwd support on Windows for example.
	○ Recent terminal working directories command (dep: Cwd tracking)
		§ This will present a quick pick of all recent terminal directories
		§ This should share code with the command history command as both will present a list and send text to the shell
		§ Should have smoke tests
		§ Considerations:
			□ Same as command history

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality on-release-notes Issue/pull request mentioned in release notes on-testplan terminal Integrated terminal issues
Projects
None yet
Development

No branches or pull requests

2 participants