Skip to content

Expose shell integration command knowledge to extensions #145234

Closed

Description

@Tyriar

Shell integration in the terminal could enable APIs like being able to listen to commands that run and get their output/exit code.

Rough example:

interface Terminal {
  executeCommand(command): Thenable<TerminalCommandResult>;
}

Activity

  1. added this to the Backlog milestone on Mar 16, 2022
  2. ClockworkV commented on Mar 17, 2022

    @ClockworkV

    I came here to request this, and here it is already.
    Being in Backlog means it'll get on the work plan eventually?

    Cheers, looking forward to this, it's the missing link for my 'debug last command line' extension!

  3. Tyriar commented on Jul 8, 2022

    @Tyriar
    ContributorAuthor

    ClockworkV backlog means it's a valid item and it may be worked on in the future. I'm pretty sure this one will happen within the next year

  4. meganrogge commented on Oct 5, 2022

    @meganrogge
    Collaborator

    Proposal:

    registerQuickFixProvider(...options: ITerminalQuickFixOptions[]): void;
    
    
    export interface ITerminalQuickFixOptions {
    	commandLineMatcher: string | RegExp;
    	outputMatcher?: ITerminalOutputMatcher;
    	getQuickFixes: TerminalQuickFixCallback;
    	exitStatus?: boolean;
    }
    export type TerminalQuickFixMatchResult = { commandLineMatch: RegExpMatchArray; outputMatch?: RegExpMatchArray | null };
    export type TerminalQuickFixAction = IAction | ITerminalQuickFixCommandAction | ITerminalQuickFixOpenerAction;
    export type TerminalQuickFixCallback = (matchResult: TerminalQuickFixMatchResult, command: ITerminalCommand) => TerminalQuickFixAction[] | TerminalQuickFixAction | undefined;
    
    export interface ITerminalQuickFixCommandAction {
    	type: 'command';
    	command: string;
    	addNewLine: boolean;
    }
    export interface ITerminalQuickFixOpenerAction {
    	type: 'opener';
    	uri: URI;
    }
    export interface ITerminalOutputMatcher {
    	/**
    	 * A string or regex to match against the unwrapped line. If this is a regex with the multiline
    	 * flag, it will scan an amount of lines equal to `\n` instances in the regex + 1.
    	 */
    	lineMatcher: string | RegExp;
    	/**
    	 * Which side of the output to anchor the {@link offset} and {@link length} against.
    	 */
    	anchor: 'top' | 'bottom';
    	/**
    	 * How far from either the top or the bottom of the butter to start matching against.
    	 */
    	offset: number;
    	/**
    	 * The number of rows to match against, this should be as small as possible for performance
    	 * reasons.
    	 */
    	length: number;
    }

    Alex Ross (@alexr00) and Ladislau Szomoru (@lszomoru) how does this look to you, as you'll be adopting this for the git extension?

  5. Tyriar commented on Oct 7, 2022

    @Tyriar
    ContributorAuthor

    Megan Rogge (@meganrogge) I've forked this off to #162950 as I realized this issue is more about general listening to commands

  6. mmisiewicz commented on Jun 3, 2023

    @mmisiewicz

    Voting for this issue. The proposed interface would exactly solve a problem I have developing an extension.

  7. lroberts7 commented on Jun 5, 2023

    @lroberts7

    +1 for this, can we get it on a roadmap plz?

  8. mmisiewicz-yext commented on Jun 30, 2023

    @mmisiewicz-yext

    Hi Megan Rogge (@meganrogge) and Daniel Imms (@Tyriar) - I've noticed this issue has been on an "iteration plan" in Nov and Oct of 2022. I'm wondering if you think it will be picked up any time soon? Thanks, really appreciate all the hard work!

  9. 133 remaining items

  10. Tyriar commented on Jun 18, 2024

    @Tyriar
    ContributorAuthor

    Moving to July for Python to adopt first and give feedback before finalizing.

  11. whitequark commented on Jun 25, 2024

    @whitequark

    Is there any way to receive a stream of raw data from a terminal that does not have shell integration? For example if I create a terminal with any command of my choice by setting shellPath to argv[0] and shellArgs to argv[1...].

    Since there's only one command that could plausibly be run in that terminal it's not necessary to try and guess which command the output comes from. The current API doesn't seem to offer anything to cover this use case, and I think it would be too limiting for my purpose.

  12. Tyriar commented on Jun 25, 2024

    @Tyriar
    ContributorAuthor

    Catherine (@whitequark) no, this is only for when shell integration is enabled. There is the related proposal for buffer access which allows reading the buffer which would probably cover your use case. #207504

  13. whitequark commented on Jun 25, 2024

    @whitequark

    Daniel Imms (@Tyriar) Thank you, this really helps!

  14. itstreefam commented on Jul 25, 2024

    @itstreefam

    I have a quick question. What is the difference between this API and vscode.proposed.terminalExecuteCommandEvent.d.ts? My current use case is grabbing the output from an executed command, and I am using vscode.proposed.terminalExecuteCommandEvent.d.ts to do so. I suppose we can also use read() from vscode.proposed.terminalShellIntegration.d.ts to read the output stream but feel free to correct me. I wonder which one would you think have a higher chance for public release. Before these two APIs I remembered having to work around with the old vscode.proposed.terminalDataWriteEvent.d.ts, so I truly appreciate the current more stable approaches you have made available. Thanks!

  15. Tyriar commented on Jul 25, 2024

    @Tyriar
    ContributorAuthor

    Tri Pham (@itstreefam) terminalExecuteCommandEvent is old and will be removed, terminalDataWriteEvent is unlikely to get finalized and may be replaced eventually with improvements upon terminalShellIntegration. terminalShellIntegration should be finalized very soon, I just need a fix a few bugs with it.

  16. Tyriar commented on Jul 30, 2024

    @Tyriar
    ContributorAuthor
  17. added a commit that references this issue on Aug 4, 2024
    929eba4
  18. added a commit that references this issue on Aug 7, 2024
  19. locked and limited conversation to collaborators on Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions