Enhance shell autocompletion with a cool new user interface and shell completion protocol #4348

Open
opened 2026-01-30 23:44:42 +00:00 by claunia · 57 comments
Owner

Originally created by @anki-code on GitHub (Oct 8, 2019).

Originally assigned to: @zadjii-msft on GitHub.

Hello! Thank you for the new interesting project!

I just want to let you know about 🚀 Upterm — really great proof of concept but it stopped because maintainer was gone. This terminal looks like 21st century terminal. Very sad that it isn't supported.

image

up30485947-aeaa5398-9a37-11e7-927c-769304744844

up29716319-95f9a8d8-89b3-11e7-8515-fcb236eb4454

image

image

Originally created by @anki-code on GitHub (Oct 8, 2019). Originally assigned to: @zadjii-msft on GitHub. Hello! Thank you for the new interesting project! I just want to let you know about [🚀 Upterm](https://github.com/railsware/upterm) — really great proof of concept but it stopped because maintainer was gone. This terminal looks like 21st century terminal. Very sad that it isn't supported. ![image](https://user-images.githubusercontent.com/1708680/66430268-6709e480-ea22-11e9-8fc0-93abaa7210fb.png) ![up30485947-aeaa5398-9a37-11e7-927c-769304744844](https://user-images.githubusercontent.com/1708680/66430295-75f09700-ea22-11e9-8da3-0ce56e483bb4.gif) ![up29716319-95f9a8d8-89b3-11e7-8515-fcb236eb4454](https://user-images.githubusercontent.com/1708680/66430307-79841e00-ea22-11e9-956b-2c053d0ac814.gif) ![image](https://user-images.githubusercontent.com/1708680/66430384-aafce980-ea22-11e9-9350-addd649b3035.png) ![image](https://user-images.githubusercontent.com/1708680/66430393-b2bc8e00-ea22-11e9-97cd-2ae1765d7037.png)
Author
Owner

@zadjii-msft commented on GitHub (Oct 24, 2019):

This looks really cool, though this looks like something the shell would have to work with the terminal to achieve.

How was Upterm providing those autocomplete suggestions? Did they have their own shell they were using, or were they somehow pulling the auto-completions from bash/zsh/git somehow?

Presuming the shell provided a list of autocompletion suggestions to the terminal, drawing the UI shouldn't be that hard. Cmd would obviously never be able to support this, but powershell core sure could. I'd be curious what kind of perf there would be for something like that, with the shell emitting a list of auto-completion suggestions after some delay/on every character typed.

Doing the collapsible json thing might be quite a bit harder however :P that definitely seems like they had a custom rolled cat that worked directly with the terminal.

@zadjii-msft commented on GitHub (Oct 24, 2019): This looks really cool, though this looks like something the shell would have to work with the terminal to achieve. How was Upterm providing those autocomplete suggestions? Did they have their own shell they were using, or were they somehow pulling the auto-completions from bash/zsh/git somehow? Presuming the shell provided a list of autocompletion suggestions to the terminal, drawing the UI shouldn't be _that_ hard. Cmd would obviously never be able to support this, but powershell core sure could. I'd be curious what kind of perf there would be for something like that, with the shell emitting a list of auto-completion suggestions after some delay/_on every character typed_. Doing the collapsible json thing might be quite a bit harder however :P that definitely seems like they had a custom rolled `cat` that worked directly with the terminal.
Author
Owner

@huoyaoyuan commented on GitHub (Nov 15, 2019):

I think you can get inspired by Visual Studio's C# Interactive and PowerShell ISE.
PowerShell already has a mechanism to collect completions, which is used by dotnet.exe.
And also, don't forget the great Language Server Protocol by Visual Studio.

@huoyaoyuan commented on GitHub (Nov 15, 2019): I think you can get inspired by Visual Studio's C# Interactive and PowerShell ISE. PowerShell already has a mechanism to collect completions, which is used by `dotnet.exe`. And also, don't forget the great Language Server Protocol by Visual Studio.
Author
Owner

@n3wt0n commented on GitHub (Feb 4, 2020):

That would be really cool, or something like the iTerm 2 autocompletion on Mac. (cmd + ;)

image

This works for both files/folder and commands

@n3wt0n commented on GitHub (Feb 4, 2020): That would be really cool, or something like the iTerm 2 autocompletion on Mac. (cmd + ;) ![image](https://user-images.githubusercontent.com/13121206/73718155-afc67580-4756-11ea-9d8e-8ea81fb2b348.png) This works for both files/folder and commands
Author
Owner

@remkop commented on GitHub (May 19, 2020):

@zadjii-msft

Cmd would obviously never be able to support this, but powershell core sure could.

Cmd could certainly achieve bash-like completion: clink enhances Cmd with tab completion, which users can customize with simple lua scripts.

While not as fancy looking as the screenshots above, it would be hugely valuable if Cmd would support this out of the box.

(More detail: see docs and pre-built completions for common tools.)

@remkop commented on GitHub (May 19, 2020): @zadjii-msft > Cmd would obviously never be able to support this, but powershell core sure could. Cmd could certainly achieve bash-like completion: [clink](https://github.com/mridgers/clink) enhances Cmd with tab completion, which users can customize with simple lua scripts. While not as fancy looking as the screenshots above, it would be hugely valuable if Cmd would support this out of the box. (More detail: see [docs](https://github.com/mridgers/clink/blob/298113a61272afa3f646a912c97e2ce34da67597/docs/clink.md#file-locations) and [pre-built completions](https://github.com/vladimir-kotikov/clink-completions) for common tools.)
Author
Owner

@zadjii-msft commented on GitHub (May 20, 2020):

I don't disagree, projects like clink and yori are great and I love them. It's just that we really can't accept any changes to cmd.exe safely 😕 This doc covers some of the reasons why.

@zadjii-msft commented on GitHub (May 20, 2020): I don't disagree, projects like clink and yori are _great_ and I love them. It's just that we really can't accept any changes to cmd.exe safely 😕 [This doc covers some of the reasons why](https://github.com/microsoft/terminal/blob/master/doc/Niksa.md#cmd).
Author
Owner

@remkop commented on GitHub (May 20, 2020):

@zadjii-msft Thank you for the clarification. Makes sense and made me realize what a great job you and your team are doing. Keep it up! (Also thanks for pointing me to yori, I did not know about that project.)

@remkop commented on GitHub (May 20, 2020): @zadjii-msft Thank you for the clarification. Makes sense and made me realize what a great job you and your team are doing. Keep it up! (Also thanks for pointing me to yori, I did not know about that project.)
Author
Owner

@just1a-person commented on GitHub (Jun 23, 2021):

Wish we had the Terminal of 2005:

image

@just1a-person commented on GitHub (Jun 23, 2021): Wish we had the Terminal of 2005: ![image](https://user-images.githubusercontent.com/75578443/123037249-f4b28100-d40b-11eb-90f4-5f230d3fa708.png)
Author
Owner

@DHowett commented on GitHub (Jun 23, 2021):

You know, apart from the "graphical" bit, this sounds like PowerShell. It accepts C# (procedural and object-oriented), you can write prompt plugins, you can stream files (and objects!), and it supports multiple hosting interfaces such as the PowerShell ISE (which is graphical!)

@DHowett commented on GitHub (Jun 23, 2021): You know, apart from the "graphical" bit, this sounds like _PowerShell_. It accepts C# (procedural and object-oriented), you can write prompt plugins, you can stream files (and objects!), and it supports multiple hosting interfaces such as the PowerShell ISE (which _is_ graphical!)
Author
Owner

@just1a-person commented on GitHub (Jul 16, 2021):

There is this new terminal called Warp: https://twitter.com/zachlloydtweets/status/1415343353164599299

I wish Windows Terminal was that radical and not just try to match existing Unix terminals' functionality (which it already has most of)

@just1a-person commented on GitHub (Jul 16, 2021): There is this new terminal called Warp: https://twitter.com/zachlloydtweets/status/1415343353164599299 I wish Windows Terminal was that radical and not just try to match existing Unix terminals' functionality (which it already has most of)
Author
Owner

@orcmid commented on GitHub (Jul 16, 2021):

There is this new terminal called Warp: https://twitter.com/zachlloydtweets/status/1415343353164599299

I wish Windows Terminal was that radical and not just try to match existing Unix terminals' functionality (which it already has most of)

I think there is a confusion of shell versus terminal and how apps are wired in. So Warp seems more integrated and purpose-built. All the questions about how one uses a terminal are about session shell use. They focus on CLI.

Since there was such a thing as stealth mode, one must presume this is to be a commercial offering. There is no hint that the code is even in the open (although there is a statement about working in public). "Stable" releases are also ratcheting pretty quickly according to the Discord. warp.dev has more. There's a nice presentation of How Warp Works. I have not found any statement about licensing or commercial use, although having forked Alacritty might be relevant, depending on how the permissive Apache License is dealt with.

@orcmid commented on GitHub (Jul 16, 2021): > There is this new terminal called Warp: https://twitter.com/zachlloydtweets/status/1415343353164599299 > > I wish Windows Terminal was that radical and not just try to match existing Unix terminals' functionality (which it already has most of) I think there is a confusion of shell versus terminal and how apps are wired in. So Warp seems more integrated and purpose-built. All the questions about how one uses a terminal are about session shell use. They focus on CLI. Since there was such a thing as stealth mode, one must presume this is to be a commercial offering. There is no hint that the code is even in the open (although there is a statement about working in public). "Stable" releases are also ratcheting pretty quickly according to the Discord. [warp.dev](https://www.warp.dev/) has more. There's a nice presentation of [How Warp Works](https://blog.warp.dev/how-warp-works/). I have not found any statement about licensing or commercial use, although having forked [Alacritty](https://github.com/alacritty/alacritty) might be relevant, depending on how the permissive Apache License is dealt with.
Author
Owner

@just1a-person commented on GitHub (Jul 16, 2021):

I think the PowerShell team (or PSReadLine) and the Windows Terminal team can work together to make something like this happen.

@just1a-person commented on GitHub (Jul 16, 2021): I think the PowerShell team (or PSReadLine) and the Windows Terminal team can work together to make something like this happen.
Author
Owner

@IgnusG commented on GitHub (Nov 17, 2021):

There’s a plug-in for the Mac terminal that offers this functionality too

https://github.com/withfig/autocomplete

@IgnusG commented on GitHub (Nov 17, 2021): There’s a plug-in for the Mac terminal that offers this functionality too https://github.com/withfig/autocomplete
Author
Owner

@IgnusG commented on GitHub (Nov 17, 2021):

There is this new terminal called Warp: https://twitter.com/zachlloydtweets/status/1415343353164599299

I wish Windows Terminal was that radical and not just try to match existing Unix terminals' functionality (which it already has most of)

This looks amazing. Hope that MS Terminal can match these features at some point. The visual blocks and auto complete/history view would be awesome.

Maybe if the plug-in interface is permissive enough it could be shipped as part of plug-ins that work together with the shell.

@IgnusG commented on GitHub (Nov 17, 2021): > There is this new terminal called Warp: https://twitter.com/zachlloydtweets/status/1415343353164599299 > > I wish Windows Terminal was that radical and not just try to match existing Unix terminals' functionality (which it already has most of) This looks amazing. Hope that MS Terminal can match these features at some point. The visual blocks and auto complete/history view would be awesome. Maybe if the plug-in interface is permissive enough it could be shipped as part of plug-ins that work together with the shell.
Author
Owner

@ntindle commented on GitHub (Nov 25, 2021):

If I wanted to work on this, is it possible or would it be better as an extension (and thus need the extension support to be completed)?

@ntindle commented on GitHub (Nov 25, 2021): If I wanted to work on this, is it possible or would it be better as an extension (and thus need the extension support to be completed)?
Author
Owner

@zadjii-msft commented on GitHub (Nov 25, 2021):

@ntindle I suppose we wouldn't need extension support to add this to the Terminal first, if we could figure out a halfway decent way of building this into the Terminal. I guess I'd be curious to hear how you planned on implementing this. From my POV there's a couple ways we could go about this, each with upsides and drawbacks, so I'm curious what you had in mind ☺️

@zadjii-msft commented on GitHub (Nov 25, 2021): @ntindle I suppose we wouldn't _need_ extension support to add this to the Terminal first, if we could figure out a halfway decent way of building this into the Terminal. I guess I'd be curious to hear how you planned on implementing this. From my POV there's a couple ways we could go about this, each with upsides and drawbacks, so I'm curious what you had in mind ☺️
Author
Owner

@ntindle commented on GitHub (Nov 26, 2021):

Hello,

To be honest, I am wildly unfamiliar with the terminal’s code base and overall architecture. I am certain I am not the best programmer for the job, but I am interested in using the final result, even if I have to build it. That said, here we go…

My initial thoughts would be that this would have a multi stage implementation at different layers with the shell and outer terminal both needing work.

The terminal would need to be able to render “panes” (I believe pane means something specific in the context of the terminal but for now I’m just referring to a generalized UI container) on top of the shell when it receives a trigger from terminal due to time since last keypress (or elsewhere with other triggers).

The profile for each shell would use the shells respective autocomplete tooling to pull the autocomplete actions out and provide them to the terminal. This would probably be one of the simplest ways to support a wide variety of actions without having to build the auto complete engine from scratch.

This interaction would be similar to how VS Code handles language servers and auto complete in that the terminal would both decide when to show the “pane” and query the shell for the appropriate next characters.

A different approach from the completion side would be to build the equivalent of language servers that provide intelligent completions using context from the shell. I think this one would be much more powerful and popular but significantly more complex to support and implement. I believe this is how the Fig example above works.

I would greatly appreciate any advice or ideas on this, even if it is to leave it to someone with a better understanding of the terminal’s code base.

@ntindle commented on GitHub (Nov 26, 2021): Hello, To be honest, I am wildly unfamiliar with the terminal’s code base and overall architecture. I am certain I am not the best programmer for the job, but I am interested in using the final result, even if I have to build it. That said, here we go… My initial thoughts would be that this would have a multi stage implementation at different layers with the shell and outer terminal both needing work. The terminal would need to be able to render “panes” (I believe pane means something specific in the context of the terminal but for now I’m just referring to a generalized UI container) on top of the shell when it receives a trigger from terminal due to time since last keypress (or elsewhere with other triggers). The profile for each shell would use the shells respective autocomplete tooling to pull the autocomplete actions out and provide them to the terminal. This would probably be one of the simplest ways to support a wide variety of actions without having to build the auto complete engine from scratch. This interaction would be similar to how VS Code handles language servers and auto complete in that the terminal would both decide when to show the “pane” and query the shell for the appropriate next characters. A different approach from the completion side would be to build the equivalent of language servers that provide intelligent completions using context from the shell. I think this one would be much more powerful and popular but significantly more complex to support and implement. I believe this is how the Fig example above works. I would greatly appreciate any advice or ideas on this, even if it is to leave it to someone with a better understanding of the terminal’s code base.
Author
Owner

@zadjii-msft commented on GitHub (Mar 28, 2022):

A tiny prototype is in dev/migrie/fhl/menu-complete-prototype dev/migrie/fhl/vscode-autocomplete-prototype

  • I hate the current design for the VT sequence. Performance is terrible. We should be able to just set the whole menu with a single sequence.
  • We probably don't need to leave the space for the icon in the menu
  • We should get rid of the alphabetical ordering for commands in the autocomplete version of the menu.
  • We may want to allow the menu to be modal, s.t. a shell could still key character keypresses, but arrows, tab, enter would go to the menu.
    • We should think hard if this is a shell-specified setting (like, a flag passed in the OSC sequence) or a terminal-side setting.
  • We probably don't need an autocomplete menu and a command palette. Or we could certainly create a simpler shared base class.
  • We should definitely get rid of the > prompt for "action mode" in the autosuggest menu cause that's obviously dumb.

As a stretch related idea: It would be really cool if the ControlCore saved working directories as it saw them, and then, you could open the auto suggest menu and it's pre-populated with a stack of your recent directories for this pane, as sendInput(cd ${path})` actions.

@zadjii-msft commented on GitHub (Mar 28, 2022): A tiny prototype is in ~[`dev/migrie/fhl/menu-complete-prototype`](https://github.com/microsoft/terminal/compare/dev/migrie/fhl/menu-complete-prototype)~ `dev/migrie/fhl/vscode-autocomplete-prototype` * I hate the current design for the VT sequence. Performance is terrible. We should be able to just set the whole menu with a single sequence. * We probably don't need to leave the space for the icon in the menu * We should get rid of the alphabetical ordering for commands in the autocomplete version of the menu. * We may want to allow the menu to be modal, s.t. a shell could still key character keypresses, but arrows, tab, enter would go to the menu. * We should think hard if this is a shell-specified setting (like, a flag passed in the OSC sequence) or a terminal-side setting. * We probably don't need an autocomplete menu _and_ a command palette. Or we could certainly create a simpler shared base class. * We should definitely get rid of the `> ` prompt for "action mode" in the autosuggest menu cause that's obviously dumb. **As a stretch related idea**: It would be really cool if the `ControlCore` saved working directories as it saw them, and then, you could open the auto suggest menu and it's pre-populated with a stack of your recent directories for this pane, as `sendInput(`cd ${path})` actions.
Author
Owner

@zadjii-msft commented on GitHub (Mar 10, 2023):

Alrighty folks, so, it's discussion time.

I've got a prototype of this out over in #14938. That's absolutely a first-draft of this experience, and there's plenty of room for improvements.

gh-3121-for-pr

Right now, the "protocol" it is using is an OSC sequence with a blob of JSON that contains a serialization of the output of the PowerShell cmdlet TabExpansion2. This is obviously terrible. It's needlessly verbose, and it's super powershell-specific. Not only that, I suspect this doesn't include all the information we'd want to send, either.

Right now, the payload of that blob looks something like:

[
    {
        "CompletionText": "Microsoft.PowerShell.Management",
        "ListItemText": "Microsoft.PowerShell.Management",
        "ResultType": 8,
        "ToolTip": "Description: \r\nModuleType: Manifest\r\nPath: C:\\program files\\powershell\\7\\Modules\\Microsoft.PowerShell.Management\\Microsoft.PowerShell.Management.psd1"
    },
    {
        "CompletionText": "Microsoft.PowerShell.Utility",
        "ListItemText": "Microsoft.PowerShell.Utility",
        "ResultType": 8,
        "ToolTip": "Description: \r\nModuleType: Manifest\r\nPath: C:\\program files\\powershell\\7\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1"
    },
    {
        "CompletionText": "PSReadLine",
        "ListItemText": "PSReadLine",
        "ResultType": 8,
        "ToolTip": "Description: Great command line editing in the PowerShell console host\r\nModuleType: Script\r\nPath: C:\\program files\\powershell\\7\\Modules\\PSReadLine\\PSReadLine.psm1"
    }
]

Which is synthensized with a powershell command like:

function Send-Completions {
    $commandLine = ""
    $cursorIndex = 0
    
    [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$commandLine, [ref]$cursorIndex)
    $completionPrefix = $commandLine

    # Get completions
    $result = "`e]633;Completions"
    if ($completionPrefix.Length -gt 0) {
        # Get and send completions
        $completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
        if ($null -ne $completions.CompletionMatches) {
            $result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
            $result += $completions.CompletionMatches | ConvertTo-Json -Compress
        }
    }
    $result += "`a"

    Write-Host -NoNewLine $result
}

Now, the point of discussion: How do we want to refine this sequence?

  • How do we make this something that pwsh, bash, zsh, fish, nu... anyone really, could emit easily?
  • Similarly, the same menu could be used by something like vim. Would it be possible there?
  • What's missing from this protocol that these other shells might also want?
  • TabExpansion2 isn't even that great as far as PowerShell is concerned - there's more elaborate completion providers that might give us more info
  • An OSC seems a little silly for this - would a DCS make more sense? an APC (ew)? What's the actual wire format look like?

A quick /cc to @Tyriar who's driving this on the VsCode terminal side.

I may also want to cc @j4james, @wez, @christianparpart who usually have opinions on this sort of thing. I'd rather get some initial design feedback here before writing a more formal spec for terminal-wg (which has kinda just become informative, not normative anyways)

@zadjii-msft commented on GitHub (Mar 10, 2023): Alrighty folks, so, it's discussion time. I've got a prototype of this out over in #14938. That's absolutely a first-draft of this experience, and there's plenty of room for improvements. ![gh-3121-for-pr](https://user-images.githubusercontent.com/18356694/222238017-1ea21ce3-2541-474f-93db-22b624296479.gif) Right now, the "protocol" it is using is an OSC sequence with a blob of JSON that contains a serialization of the output of the PowerShell cmdlet `TabExpansion2`. **This is obviously terrible**. It's needlessly verbose, and it's super powershell-specific. Not only that, I suspect this doesn't include all the information we'd want to send, either. Right now, the payload of that blob looks something like: ```json [ { "CompletionText": "Microsoft.PowerShell.Management", "ListItemText": "Microsoft.PowerShell.Management", "ResultType": 8, "ToolTip": "Description: \r\nModuleType: Manifest\r\nPath: C:\\program files\\powershell\\7\\Modules\\Microsoft.PowerShell.Management\\Microsoft.PowerShell.Management.psd1" }, { "CompletionText": "Microsoft.PowerShell.Utility", "ListItemText": "Microsoft.PowerShell.Utility", "ResultType": 8, "ToolTip": "Description: \r\nModuleType: Manifest\r\nPath: C:\\program files\\powershell\\7\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1" }, { "CompletionText": "PSReadLine", "ListItemText": "PSReadLine", "ResultType": 8, "ToolTip": "Description: Great command line editing in the PowerShell console host\r\nModuleType: Script\r\nPath: C:\\program files\\powershell\\7\\Modules\\PSReadLine\\PSReadLine.psm1" } ] ``` Which is synthensized with a powershell command like: ```ps1 function Send-Completions { $commandLine = "" $cursorIndex = 0 [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$commandLine, [ref]$cursorIndex) $completionPrefix = $commandLine # Get completions $result = "`e]633;Completions" if ($completionPrefix.Length -gt 0) { # Get and send completions $completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex if ($null -ne $completions.CompletionMatches) { $result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);" $result += $completions.CompletionMatches | ConvertTo-Json -Compress } } $result += "`a" Write-Host -NoNewLine $result } ``` Now, the point of discussion: **How do we want to refine this sequence?** * How do we make this something that `pwsh`, `bash`, `zsh`, `fish`, `nu`... anyone really, could emit easily? * Similarly, the same menu could be used by something like `vim`. Would it be possible there? * What's missing from this protocol that these other shells might also want? * `TabExpansion2` isn't even that great as far as PowerShell is concerned - there's more elaborate completion providers that might give us more info * An OSC seems a little silly for this - would a DCS make more sense? an APC (ew)? What's the actual wire format look like? A quick /cc to @Tyriar who's driving this on the VsCode terminal side. I may also want to cc @j4james, @wez, @christianparpart who usually have opinions on this sort of thing. I'd rather get some initial design feedback here before writing a more formal spec for terminal-wg (which has kinda just become _informative_, not _normative_ anyways)
Author
Owner

@wez commented on GitHub (Mar 10, 2023):

Neat!

The fig.io folks may have some thoughts on this, their thing is bolting similar looking functionality on top of existing terminals through a pty and IME sandwich. https://github.com/withfig/autocomplete in case you haven't seen it. cc: @brendanfalk; not sure how much you're up for sharing/collaborating on this, but I suspect that you probably already have some OSC sequences that are similar in purpose!

May also be worth looping in say, one of the fish folks, to get their thoughts from the client side. I actually don't know how their line editor works so I don't know if they would be a prime candidate for this.

@wez commented on GitHub (Mar 10, 2023): Neat! The fig.io folks may have some thoughts on this, their thing is bolting similar looking functionality on top of existing terminals through a pty and IME sandwich. https://github.com/withfig/autocomplete in case you haven't seen it. cc: @brendanfalk; not sure how much you're up for sharing/collaborating on this, but I suspect that you probably already have some OSC sequences that are similar in purpose! May also be worth looping in say, one of the fish folks, to get their thoughts from the client side. I actually don't know how their line editor works so I don't know if they would be a prime candidate for this.
Author
Owner

@Tyriar commented on GitHub (Mar 10, 2023):

@wez afaik fig is based on using shell integration to extract the command args and then everything is doing using these handwritten specs. My preferred approach would be to use the shell's native asutocomplete providers (TabExpansion2/etc. for pwsh, zsh-autocomplete, bash complete, etc.), instead of re-inventing the wheel and having a parallel set of completions that comes with versioning problems.

In VSCode this is currently behind an experimental flag "terminal.integrated.shellIntegration.suggestEnabled": true, but it's kind of broken atm had some critical work that took my attention away for now.

@Tyriar commented on GitHub (Mar 10, 2023): @wez afaik fig is based on using shell integration to extract the command args and then everything is doing using these handwritten specs. My preferred approach would be to use the shell's native asutocomplete providers (TabExpansion2/etc. for pwsh, zsh-autocomplete, bash complete, etc.), instead of re-inventing the wheel and having a parallel set of completions that comes with versioning problems. In VSCode this is currently behind an experimental flag `"terminal.integrated.shellIntegration.suggestEnabled": true`, but it's kind of broken atm had some critical work that took my attention away for now.
Author
Owner

@j4james commented on GitHub (Mar 10, 2023):

Unless you have a boat load of shells that are lining up to use this new functionality, I'm of the opinion that we're better off just hacking something on top of the FTCS sequences (which I'm assuming is what fig is doing). That doesn't require any buy-in from the shells, other than the ability to modify the prompt, which even cmd.exe can handle.

Otherwise we're guaranteed to get people complaining about the functionality not working in their favorite shell. And we can't blame the shell if there other terminals or tools that can achieve more or less the same thing without any special shell cooperation.

Although maybe there is a middle ground, where we start with an FTCS-based approach (using some minimalist autocomplete specs bundled with the terminal), but a shell can still provide additional context and custom suggestions (with your new escape sequence) if they want to enhance that experience.

@j4james commented on GitHub (Mar 10, 2023): Unless you have a boat load of shells that are lining up to use this new functionality, I'm of the opinion that we're better off just hacking something on top of the FTCS sequences (which I'm assuming is what fig is doing). That doesn't require any buy-in from the shells, other than the ability to modify the prompt, which even cmd.exe can handle. Otherwise we're guaranteed to get people complaining about the functionality not working in their favorite shell. And we can't blame the shell if there other terminals or tools that can achieve more or less the same thing without any special shell cooperation. Although maybe there is a middle ground, where we start with an FTCS-based approach (using some minimalist autocomplete specs bundled with the terminal), but a shell can still provide additional context and custom suggestions (with your new escape sequence) if they want to enhance that experience.
Author
Owner

@zadjii-msft commented on GitHub (Mar 16, 2023):

I like half agree but also half don't. I really don't love the fig-style completion specs that are external to the actual source of the command. That just sounds like a versioning nightmare to me. Plus, we'd have to also maintain a enormous list of completion data, which would suddenly stop working as soon as you encounter a previously un-spec'd command.

That being said, you're right. I don't suspect there are a lot of other shells lining up to add this / support this. I'm pretty confident there'd never be a way to support something like this for cmd.exe.

I think the middle-ground approach you described is something I'd more like to get to in the long-term. This UI is something I'm gonna start using for a whole bunch of stuff real soon, not just shell completions. In the fullness of time, I want extensions to be able to plumb their own suggestions into it. So you could have a fig extension, and then hit your figSuggestions keybinding and that would let fig give back suggestions based on the CWD and currently typed command (as powered by FTCS commands).

But I think there's room for everyone here. I think there's also space for the shell to give definitive suggestions, if it knows them. Maybe not something built-in to zsh, but something that a plugin could invoke. I really need to go research more how completions work for other shells. Do I dare start cc'ing devs on other shells? I may need to 😬

@zadjii-msft commented on GitHub (Mar 16, 2023): I like half agree but also half don't. I really don't love the fig-style completion specs that are external to the actual source of the command. That just sounds like a versioning nightmare to me. Plus, we'd have to also maintain a enormous list of completion data, which would suddenly stop working as soon as you encounter a previously un-spec'd command. That being said, you're right. I don't suspect there are a lot of other shells lining up to add this / support this. I'm pretty confident there'd _never_ be a way to support something like this for `cmd.exe`. I think the middle-ground approach you described is something I'd more like to get to in the long-term. This UI is something I'm gonna start using for a whole bunch of stuff real soon, not just shell completions. In the fullness of time, I want extensions to be able to plumb their own suggestions into it. So you could have a `fig` extension, and then hit your `figSuggestions` keybinding and that would let `fig` give back suggestions based on the CWD and currently typed command (as powered by FTCS commands). But I think there's room for everyone here. I think there's also space for the shell to give definitive suggestions, if it knows them. Maybe not something built-in to `zsh`, but something that a plugin could invoke. I really need to go research more how completions work for other shells. Do I dare start cc'ing devs on other shells? I may need to 😬
Author
Owner

@Tyriar commented on GitHub (Mar 16, 2023):

Something like that is what I was thinking, first class support for native shell completion engines and allowing fig specs to provide fallback completions via an extension.

@Tyriar commented on GitHub (Mar 16, 2023): Something like that is what I was thinking, first class support for native shell completion engines and allowing fig specs to provide fallback completions via an extension.
Author
Owner

@Araxeus commented on GitHub (Mar 17, 2023):

I really need to go research more how completions work for other shells

Nushell has custom completions: https://www.nushell.sh/book/custom_completions.html

I love how they handle custom completions, that could even enable AI powered suggestions pretty easily

I'm using their recommended external completion engine https://github.com/rsteube/carapace-bin and it's working great in windows terminal
(here's a nice blog post about carapace)

Screenshot of my setup

image

@Araxeus commented on GitHub (Mar 17, 2023): > I really need to go research more how completions work for other shells [Nushell](https://github.com/nushell/nushell) has custom completions: https://www.nushell.sh/book/custom_completions.html I love how they handle custom completions, that could even enable AI powered suggestions pretty easily I'm using their recommended external completion engine https://github.com/rsteube/carapace-bin and it's working great in windows terminal (here's a nice [blog post](https://dev.to/rsteube/a-pragmatic-approach-to-shell-completion-4gp0) about carapace) <details> <summary><i>Screenshot of my setup</i></summary> ![image](https://user-images.githubusercontent.com/78568641/226058900-9d528d5a-5458-445a-802a-6061d9ec90b3.png) </details>
Author
Owner

@Welding-Torch commented on GitHub (Sep 14, 2023):

IMAGE ALT TEXT

James McParlane has had success implementing a kind of suggestions system, and it is running on Windows Terminal. This video released just 2 weeks ago, so I thought I'd bring it to the attention of the developers here.

@Welding-Torch commented on GitHub (Sep 14, 2023): [![IMAGE ALT TEXT](http://img.youtube.com/vi/NxsaHxON350/0.jpg)](https://youtu.be/NxsaHxON350?si=SaViU9Yz731vGTbc&t=540 "I'm Re-Imagining the Command Line Interpreter") James McParlane has had success implementing a kind of suggestions system, and it is running on Windows Terminal. This video released just 2 weeks ago, so I thought I'd bring it to the attention of the developers here.
Author
Owner

@zadjii-msft commented on GitHub (Sep 26, 2023):

Alright, so notes on enabling the version we shipped in 1.19 are in https://github.com/microsoft/terminal/wiki/Experimental-Shell-Completion-Menu.

I'm fully intending to replace that sequence, but that's a place to start playing with it.

@zadjii-msft commented on GitHub (Sep 26, 2023): Alright, so notes on enabling the version we shipped in 1.19 are in https://github.com/microsoft/terminal/wiki/Experimental-Shell-Completion-Menu. I'm fully intending to replace that sequence, but that's a place to start playing with it.
Author
Owner

@AmyJeanes commented on GitHub (Sep 26, 2023):

Thank you @zadjii-msft and team it looks great!

Unfortunately I've not been able to get it working after setting up shell integration which does work, ctrl+space just appears to do nothing 😢

I've debugged it to ensure that it is actually triggering PowerShell (7.3.7) to send the completions by removing the special character markers and the setting ("experimental.enableShellCompletion": true) is definitely on at the root of the config file.

Windows Terminal Preview version is 1.19.2682.0

Not sure where the best place to ask for help with that is, in this issue, a new issue or a discussion - cheers

@AmyJeanes commented on GitHub (Sep 26, 2023): Thank you @zadjii-msft and team it looks great! Unfortunately I've not been able to get it working after setting up shell integration which does work, ctrl+space just appears to do nothing 😢 I've debugged it to ensure that it is actually triggering PowerShell (7.3.7) to send the completions by removing the special character markers and the setting (`"experimental.enableShellCompletion": true`) is definitely on at the root of the config file. Windows Terminal Preview version is 1.19.2682.0 Not sure where the best place to ask for help with that is, in this issue, a new issue or a discussion - cheers
Author
Owner

@zadjii-msft commented on GitHub (Sep 26, 2023):

WELP We're doing a bug bash with the team right now and iT wOrKs On My MaChInE but it doesn't on @carlos-zamora's and we're trying to debug as we speak

@zadjii-msft commented on GitHub (Sep 26, 2023): WELP We're doing a bug bash with the team right now and iT wOrKs On My MaChInE but it doesn't on @carlos-zamora's and we're trying to debug as we speak
Author
Owner

@zadjii-msft commented on GitHub (Sep 26, 2023):

omfg I typo'd the wiki.

It's experimental.enableShellCompletionMenu

@zadjii-msft commented on GitHub (Sep 26, 2023): omfg I typo'd the wiki. It's `experimental.enableShellCompletionMenu`
Author
Owner

@AmyJeanes commented on GitHub (Sep 26, 2023):

Thanks it works now!! 😄

image

@AmyJeanes commented on GitHub (Sep 26, 2023): Thanks it works now!! 😄 ![image](https://github.com/microsoft/terminal/assets/2363642/31fbcf50-92d2-46c4-be9a-f6b6dda81481)
Author
Owner

@lost22git commented on GitHub (Sep 26, 2023):

Screenshot 2023-09-27 062555

and

Screenshot 2023-09-27 062644

Looks like the second one is more efficient

@lost22git commented on GitHub (Sep 26, 2023): ![Screenshot 2023-09-27 062555](https://github.com/microsoft/terminal/assets/65008815/31089905-d7d9-4b0a-be2f-d05288ba3cec) and ![Screenshot 2023-09-27 062644](https://github.com/microsoft/terminal/assets/65008815/fc78036b-ce32-4919-8b37-5bc0223ed9ff) Looks like the second one is more efficient
Author
Owner

@sanket-bhalerao commented on GitHub (Sep 27, 2023):

i still see the old prompt
image

@sanket-bhalerao commented on GitHub (Sep 27, 2023): i still see the old prompt ![image](https://github.com/microsoft/terminal/assets/9264813/ebad2a63-542c-43f9-9134-d51853efab9d)
Author
Owner

@lost22git commented on GitHub (Sep 27, 2023):

i still see the old prompt image

maybe you forgot to restart wtp?

@lost22git commented on GitHub (Sep 27, 2023): > i still see the old prompt ![image](https://user-images.githubusercontent.com/9264813/270882434-ebad2a63-542c-43f9-9134-d51853efab9d.png) maybe you forgot to restart wtp?
Author
Owner

@christianparpart commented on GitHub (Sep 27, 2023):

Hi,

I know I am very late (private life and such), but I indeed wanted to drop some comments, because I think we should avoid re-inventing the wheel for every MxN component in the huge matrix of terminal emulators on the one dimension and shell programs / CLI apps on the other dimension.

What I imagine is some kind of at least shell-agnostic auto-complete system (I recently talked to some ex-Fig and other TE devs about it) that a shell simply needs to hook into the protocol and then can use "One common shared code completion definition database". I learned that this is what fix is already doing, but they had issues when it came to tools with conflicting names. I suggested triggers (like Github Actions' CI if: statement).

Now. What could the terminal offer here? Well, Fig does provide its own intermediate layer (horrorble performance impact) that also works by interchanging JSON payload via OSC (similar to you as of right now). I'd actually probably do it more or less the same.
The shell now however should probably invent some VT sequences to make popups work. That may indeed be an OSC (in order to allow string parameters), such a popup should be flexible enough to allow the user to choose an item from a list of items, and have each item in that list annotated (probably in markdown syntax, as it's most well known, little to no added complexity, easy to understand by any future completion contributor). That popup would then reply back to the TE app with the selected item. There a CSI seq could suffice (as returning an index to the selected choice could be enough), but having OSC might work too (to make request and response somewhat similar).

I soon wanted to design a VT extension draft for specifying general tooltips, that shells (including pwsh) could make use of to display LSP-like tooltips on hover events as well. So there is plenty of room for improvement for the TE/TUI/CLI space. :-)

How do we make this something that pwsh, bash, zsh, fish, nu... anyone really, could emit easily?

Basing the work that Fig did for an at least initial central completion definition database. I think that should work. The specific shells that want to make use of these, simply implement their own integration and read those YAML/JSON completion definitions and evaluate upon them. Dynamic context might be possibly given too (should in fact be supported), and initially I thought, giving these in basic sh/bash syntax should suffice. But I completely forgot about pwsh (and its primary platform: Win) being entirely different. 🤔

Similarly, the same menu could be used by something like vim. Would it be possible there?

This is basically what I also proposed above with a hopefully well designed VT sequence extension. I didn't think about vim, but rather about shell programs here.

An OSC seems a little silly for this - would a DCS make more sense? an APC (ew)? What's the actual wire format look like?

Looking at all those VT sequence groups (ESC, CSI, DCS, OSC, PM). I at first would have chosen DCS, because it makes me think that D (device) is the TE. But IIRC there were terminals that didn't parse DCS correctly. That might only apply to somewhat oldish/rubbish TEs though. Not sure that should be relevant to anyone wanted to implement such a protocol extension. The big diff probably is, that OSC's by habbit seem to always start with a number as identifier, for DCS there is no such grouping (as of yet). Surely, @j4james knows better. :)

In the end, @zadjii-msft, whatever you come up with. I'd be more than happy if it will be something that is implementable by other TEs as well, not just on Windows, but ideally also on non-Windows platforms, and not just for pwsh, but ideally also for other shell programs or even apps.

@christianparpart commented on GitHub (Sep 27, 2023): Hi, I know I am very late (private life and such), but I indeed wanted to drop some comments, because I think we should avoid re-inventing the wheel for every MxN component in the huge matrix of terminal emulators on the one dimension and shell programs / CLI apps on the other dimension. What I imagine is some kind of at least shell-agnostic auto-complete system (I recently talked to some ex-Fig and other TE devs about it) that a shell simply needs to hook into the protocol and then can use "One common shared code completion definition database". I learned that this is what fix is already doing, but they had issues when it came to tools with conflicting names. I suggested triggers (like Github Actions' CI `if:` statement). Now. What could the terminal offer here? Well, Fig does provide its own intermediate layer (horrorble performance impact) that also works by interchanging JSON payload via OSC (similar to you as of right now). I'd actually probably do it more or less the same. The shell now however should probably invent some VT sequences to make popups work. That may indeed be an OSC (in order to allow string parameters), such a popup should be flexible enough to allow the user to choose an item from a list of items, and have each item in that list annotated (probably in markdown syntax, as it's most well known, little to no added complexity, easy to understand by any future completion contributor). That popup would then reply back to the TE app with the selected item. There a CSI seq could suffice (as returning an index to the selected choice could be enough), but having OSC might work too (to make request and response somewhat similar). I soon wanted to design a VT extension draft for specifying general tooltips, that shells (including pwsh) could make use of to display LSP-like tooltips on hover events as well. So there is plenty of room for improvement for the TE/TUI/CLI space. :-) > How do we make this something that pwsh, bash, zsh, fish, nu... anyone really, could emit easily? Basing the work that Fig did for an at least initial central completion definition database. I think that should work. The specific shells that want to make use of these, simply implement their own integration and read those YAML/JSON completion definitions and evaluate upon them. Dynamic context might be possibly given too (should in fact be supported), and initially I thought, giving these in basic sh/bash syntax should suffice. But I completely forgot about pwsh (and its primary platform: Win) being entirely different. 🤔 > Similarly, the same menu could be used by something like vim. Would it be possible there? This is basically what I also proposed above with a hopefully well designed VT sequence extension. I didn't think about vim, but rather about shell programs here. > An OSC seems a little silly for this - would a DCS make more sense? an APC (ew)? What's the actual wire format look like? Looking at all those VT sequence groups (ESC, CSI, DCS, OSC, PM). I at first would have chosen DCS, because it makes me think that D (device) is the TE. But IIRC there were terminals that didn't parse DCS correctly. That might only apply to somewhat oldish/rubbish TEs though. Not sure that should be relevant to anyone wanted to implement such a protocol extension. The big diff probably is, that OSC's by habbit seem to always start with a number as identifier, for DCS there is no such grouping (as of yet). Surely, @j4james knows better. :) In the end, @zadjii-msft, whatever you come up with. I'd be more than happy if it will be something that is implementable by other TEs as well, not just on Windows, but ideally also on non-Windows platforms, and not just for pwsh, but ideally also for other shell programs or even apps.
Author
Owner

@hanhwi commented on GitHub (Sep 27, 2023):

I just tried the profile and settings in the wiki. It seems that the terminal cannot process the character sequences for command suggestions. Which version should I use for this feature? I am currently on v 1.19.2682.0

image

@hanhwi commented on GitHub (Sep 27, 2023): I just tried the profile and settings in the wiki. It seems that the terminal cannot process the character sequences for command suggestions. Which version should I use for this feature? I am currently on v 1.19.2682.0 ![image](https://github.com/microsoft/terminal/assets/2665195/fc3598a9-11ce-434f-9910-886a6e9a66cc)
Author
Owner

@zadjii-msft commented on GitHub (Sep 27, 2023):

  1. Op, I should probably make a note about ctrl+space, since lots of folks already use that for MenuComplete. You may want to pick different keys
  2. welp I forgot that Windows PowerShell (5.x) doesn't support `e as an escape character. I'll need to edit the sample to use the whole [char]0x1b thing for back-compat.
  3. @christianparpart Oh don't you worry, I think I've got almost all the same thoughts as you in this space. Sometime over the next few months I wanna take what we have here, mostly throw it out, and propose a different version to terminal-wg1 . Shell-agnostic, client-agnostic, and terminal-agnostic.

  1. terminal-wg is of course, mostly dead, but it is still a place to go. I'm not sure that consensus building is something that'll happen there. I still think there's room for it to be informative, but not normative. ↩︎

@zadjii-msft commented on GitHub (Sep 27, 2023): 1. Op, I should probably make a note about <kbd>ctrl+space</kbd>, since lots of folks already use that for MenuComplete. You may want to pick different keys 2. welp I forgot that Windows PowerShell (5.x) doesn't support <code>\`e</code> as an escape character. I'll need to edit the sample to use the whole `[char]0x1b` thing for back-compat. 3. @christianparpart Oh don't you worry, I think I've got almost all the same thoughts as you in this space. Sometime over the next few months I wanna take what we have here, mostly throw it out, and propose a different version to terminal-wg[^1]. Shell-agnostic, client-agnostic, and terminal-agnostic. [^1]: terminal-wg is of course, mostly dead, but it is still a place to go. I'm not sure that _consensus building_ is something that'll happen there. I still think there's room for it to be informative, but not normative.
Author
Owner

@sanket-bhalerao commented on GitHub (Sep 27, 2023):

i still see the old prompt image

maybe you forgot to restart wtp?

i have restarted the terminal several times, but still see the same result.

@sanket-bhalerao commented on GitHub (Sep 27, 2023): > > i still see the old prompt ![image](https://user-images.githubusercontent.com/9264813/270882434-ebad2a63-542c-43f9-9134-d51853efab9d.png) > > maybe you forgot to restart wtp? i have restarted the terminal several times, but still see the same result.
Author
Owner

@zadjii-msft commented on GitHub (Sep 27, 2023):

@sanket-bhalerao mind filing a new issue, with your settings.json file and your PowerShell profile? We can debug over there, and report findings back to this thread ☺️

@zadjii-msft commented on GitHub (Sep 27, 2023): @sanket-bhalerao mind filing a new issue, with your [settings.json file](https://github.com/microsoft/terminal/wiki/Frequently-Asked-Questions-(FAQ)#where-can-i-find-the-settings-file) and your PowerShell profile? We can debug over there, and report findings back to this thread ☺️
Author
Owner

@j4james commented on GitHub (Sep 27, 2023):

But IIRC there were terminals that didn't parse DCS correctly.

@christianparpart The Windows 10 console is one such terminal. The issue was fixed years ago, but I don't think Windows 10 gets updates anymore. But it's not a problem as long as apps use some form of feature detection before using the sequence. I wouldn't recommend apps use any string sequence without feature detection.

The big diff probably is, that OSC's by habbit seem to always start with a number as identifier, for DCS there is no such grouping (as of yet).

The DCS intermediate-final characters are the equivalent of the OSC number. You can think of it as a self terminating base-16 number, so you have something like 65 times more range for a 4 byte value.

@j4james commented on GitHub (Sep 27, 2023): > But IIRC there were terminals that didn't parse DCS correctly. @christianparpart The Windows 10 console is one such terminal. The issue was fixed years ago, but I don't think Windows 10 gets updates anymore. But it's not a problem as long as apps use some form of feature detection before using the sequence. I wouldn't recommend apps use *any* string sequence without feature detection. > The big diff probably is, that OSC's by habbit seem to always start with a number as identifier, for DCS there is no such grouping (as of yet). The DCS intermediate-final characters are the equivalent of the OSC number. You can think of it as a self terminating base-16 number, so you have something like 65 times more range for a 4 byte value.
Author
Owner

@sanket-bhalerao commented on GitHub (Sep 28, 2023):

@sanket-bhalerao mind filing a new issue, with your settings.json file and your PowerShell profile? We can debug over there, and report findings back to this thread ☺️

@zadjii-msft I have raised a bug: https://github.com/microsoft/terminal/issues/16053
UPDATE: I added incorrect configs at incorrect places. after @zadjii-msft pointed it out and I corrected the configs the feature is working as expected :)

@sanket-bhalerao commented on GitHub (Sep 28, 2023): > @sanket-bhalerao mind filing a new issue, with your [settings.json file](https://github.com/microsoft/terminal/wiki/Frequently-Asked-Questions-(FAQ)#where-can-i-find-the-settings-file) and your PowerShell profile? We can debug over there, and report findings back to this thread ☺️ @zadjii-msft I have raised a bug: https://github.com/microsoft/terminal/issues/16053 UPDATE: I added incorrect configs at incorrect places. after @zadjii-msft pointed it out and I corrected the configs the feature is working as expected :)
Author
Owner

@rsteube commented on GitHub (Sep 28, 2023):

fyi Powershell supports colored completion using escape codes:

default

terminal

@rsteube commented on GitHub (Sep 28, 2023): fyi Powershell supports colored completion using escape codes: ![default](https://github.com/microsoft/terminal/assets/9090290/43131122-976d-4e9b-aa3e-525f01c712a3) ![terminal](https://github.com/microsoft/terminal/assets/9090290/c8a61ae2-258f-44df-9d81-b6acef9df3e8)
Author
Owner

@jerkovicl commented on GitHub (Sep 29, 2023):

@rsteube how did you configure this?

@jerkovicl commented on GitHub (Sep 29, 2023): @rsteube how did you configure this?
Author
Owner

@rsteube commented on GitHub (Sep 29, 2023):

@jerkovicl Windows Terminal according to the wiki, the completions are custom.
Shouldn't normally be an issue though, i'm using the powershell completions a bit differently.

@rsteube commented on GitHub (Sep 29, 2023): @jerkovicl Windows Terminal according to the wiki, the completions are [custom](https://github.com/rsteube/carapace-bin). Shouldn't normally be an issue though, i'm using the powershell completions a bit differently.
Author
Owner

@jerkovicl commented on GitHub (Sep 29, 2023):

@rsteube yeah i have meant the color part and the command description

@jerkovicl commented on GitHub (Sep 29, 2023): @rsteube yeah i have meant the color part and the command description
Author
Owner

@rsteube commented on GitHub (Sep 29, 2023):

I'm adding it to the ListItemText instead of the ToolTip.

using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Function _git_completer {
    [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingInvokeExpression", "", Scope="Function", Target="*")]
    param($wordToComplete, $commandAst, $cursorPosition)
    $commandElements = $commandAst.CommandElements

    # double quoted value works but seems single quoted needs some fixing (e.g. "example 'acti" -> "example acti")
    $elems = @()
    foreach ($_ in $commandElements) {
      if ($_.Extent.StartOffset -gt $cursorPosition) {
          break
      }
      $t = $_.Extent.Text
      if ($_.Extent.EndOffset -gt $cursorPosition) {
          $t = $t.Substring(0, $_.Extent.Text.get_Length() - ($_.Extent.EndOffset - $cursorPosition))
      }

      if ($t.Substring(0,1) -eq "'"){
        $t = $t.Substring(1)
      }
      if ($t.get_Length() -gt 0 -and $t.Substring($t.get_Length()-1) -eq "'"){
        $t = $t.Substring(0,$t.get_Length()-1)
      }
      if ($t.get_Length() -eq 0){
        $t = '""'
      }
      $elems += $t.replace('`,', ',') # quick fix
    }

    $completions = @(
      if (!$wordToComplete) {
        carapace git powershell $($elems| ForEach-Object {$_}) '' | ConvertFrom-Json | ForEach-Object { [CompletionResult]::new($_.CompletionText, $_.ListItemText.replace('`e[', "`e["), [CompletionResultType]::ParameterValue, $_.ToolTip) }
      } else {
        carapace git powershell $($elems| ForEach-Object {$_}) | ConvertFrom-Json | ForEach-Object { [CompletionResult]::new($_.CompletionText, $_.ListItemText.replace('`e[', "`e["), [CompletionResultType]::ParameterValue, $_.ToolTip) }
      }
    )

    if ($completions.count -eq 0) {
      return "" # prevent default file completion
    }

    $completions
}
Register-ArgumentCompleter -Native -CommandName 'git' -ScriptBlock (Get-Item "Function:_git_completer").ScriptBlock
@rsteube commented on GitHub (Sep 29, 2023): I'm adding it to the `ListItemText` instead of the `ToolTip`. ```powershell using namespace System.Management.Automation using namespace System.Management.Automation.Language Function _git_completer { [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingInvokeExpression", "", Scope="Function", Target="*")] param($wordToComplete, $commandAst, $cursorPosition) $commandElements = $commandAst.CommandElements # double quoted value works but seems single quoted needs some fixing (e.g. "example 'acti" -> "example acti") $elems = @() foreach ($_ in $commandElements) { if ($_.Extent.StartOffset -gt $cursorPosition) { break } $t = $_.Extent.Text if ($_.Extent.EndOffset -gt $cursorPosition) { $t = $t.Substring(0, $_.Extent.Text.get_Length() - ($_.Extent.EndOffset - $cursorPosition)) } if ($t.Substring(0,1) -eq "'"){ $t = $t.Substring(1) } if ($t.get_Length() -gt 0 -and $t.Substring($t.get_Length()-1) -eq "'"){ $t = $t.Substring(0,$t.get_Length()-1) } if ($t.get_Length() -eq 0){ $t = '""' } $elems += $t.replace('`,', ',') # quick fix } $completions = @( if (!$wordToComplete) { carapace git powershell $($elems| ForEach-Object {$_}) '' | ConvertFrom-Json | ForEach-Object { [CompletionResult]::new($_.CompletionText, $_.ListItemText.replace('`e[', "`e["), [CompletionResultType]::ParameterValue, $_.ToolTip) } } else { carapace git powershell $($elems| ForEach-Object {$_}) | ConvertFrom-Json | ForEach-Object { [CompletionResult]::new($_.CompletionText, $_.ListItemText.replace('`e[', "`e["), [CompletionResultType]::ParameterValue, $_.ToolTip) } } ) if ($completions.count -eq 0) { return "" # prevent default file completion } $completions } Register-ArgumentCompleter -Native -CommandName 'git' -ScriptBlock (Get-Item "Function:_git_completer").ScriptBlock ```
Author
Owner

@jerkovicl commented on GitHub (Sep 29, 2023):

@rsteube oh cool, thx for snippet:)

@jerkovicl commented on GitHub (Sep 29, 2023): @rsteube oh cool, thx for snippet:)
Author
Owner

@rsteube commented on GitHub (Sep 29, 2023):

It's on scoop and winget if you want to try it yourself.
Just add this to your profile and it should work:

# ~/.config/powershell/Microsoft.PowerShell_profile.ps1
Set-PSReadLineOption -Colors @{ "Selection" = "`e[7m" }
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
carapace _carapace | Out-String | Invoke-Expression
@rsteube commented on GitHub (Sep 29, 2023): It's on [scoop](https://rsteube.github.io/carapace-bin/installation.html#scoop) and [winget](https://rsteube.github.io/carapace-bin/installation.html#winget) if you want to try it yourself. Just add this to your profile and it should work: ```powershell # ~/.config/powershell/Microsoft.PowerShell_profile.ps1 Set-PSReadLineOption -Colors @{ "Selection" = "`e[7m" } Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete carapace _carapace | Out-String | Invoke-Expression ```
Author
Owner

@jerkovicl commented on GitHub (Sep 29, 2023):

@rsteube thx, i installed and set it all up, it works:)

@jerkovicl commented on GitHub (Sep 29, 2023): @rsteube thx, i installed and set it all up, it works:)
Author
Owner

@Jaykul commented on GitHub (Dec 6, 2023):

Is there any way to have the completion menu support typing to narrow down the list?

@Jaykul commented on GitHub (Dec 6, 2023): Is there any way to have the completion menu support typing to narrow down the list?
Author
Owner

@Tyriar commented on GitHub (Dec 7, 2023):

FYI thanks to some contributions from @cpendery you can once again enable suggest in VS Code's terminal ("terminal.integrated.shellIntegration.suggestEnabled": true) starting from the next insiders build which should ship sometime in the next few days:

Recording 2023-12-07 at 06 28 43

It's still rough around the edges and not close to feature complete, but I believe we fixed the show stopper bug that bricks the terminal 😅. Here's the issue tracking the feature https://github.com/microsoft/vscode/issues/154662

@Tyriar commented on GitHub (Dec 7, 2023): FYI thanks to some contributions from @cpendery you can once again enable suggest in VS Code's terminal (`"terminal.integrated.shellIntegration.suggestEnabled": true`) starting from the next insiders build which should ship sometime in the next few days: ![Recording 2023-12-07 at 06 28 43](https://github.com/microsoft/terminal/assets/2193314/7069f11e-2bb0-46f5-80a2-3c7df49300c5) It's still rough around the edges and not close to feature complete, but I believe we fixed the show stopper bug that bricks the terminal 😅. Here's the issue tracking the feature https://github.com/microsoft/vscode/issues/154662
Author
Owner

@cereschen commented on GitHub (Dec 23, 2023):

I have implemented the most basic fig like automatic completion, git.json is generated by the npm package @ withfig/autocomplete/build/git

import * as fig from '@withfig/autocomplete/build/git'
import { writeFileSync } from 'fs'
writeFileSync('./git.json',JSON.stringify(fig.default))

Note that I changed the shortcut key to ctrl+b

$directory = (Split-Path -Parent $PROFILE)
$jsonFilePath = Join-Path -Path $directory -ChildPath 'Completions/git.json'
$jsonContent = Get-Content -Raw -Path $jsonFilePath
$jsonObject = $jsonContent | ConvertFrom-Json
function Get-Items {
  param (
    $obj
  )
  $array = @()
  $mergedArray = $obj.subcommands + $obj.options
  $mergedArray | ForEach-Object {
    $name = $_.name
    $CompletionText = $_.name
    if ($_.name.GetType().BaseType.Name -eq "Array") {
      $name = $name -join "  "
      $CompletionText = $_.name[0]
    }
    $description = $_.description
    $newObject = New-Object PSObject -Property @{
      CompletionText = $CompletionText
      ListItemText   = $name + "   " + $description
      ResultType     = 2
      ToolTip        = $description
    }
    $array += $newObject
  }
  return $array
}
function Send-Completions {
  $commandLine = ""
  $cursorIndex = 0
  [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$commandLine, [ref]$cursorIndex)
  $completionPrefix = $commandLine
  $result2 = "`e]633;Completions"
  # $result = "`e]633;Completions"
  if ($completionPrefix.Length -gt 0) {
    $completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
    if ($null -ne $completions.CompletionMatches) {
      # $result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
      # $result += $completions.CompletionMatches | ConvertTo-Json -Compress
      $result2 += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
      $subStr = $completionPrefix.Substring(0, $cursorIndex)
      $strArray = $subStr -split '\s+'
      $pushItem = $jsonObject.subcommands | Where-Object { $_.name -eq $strArray[1] }
      if ($null -ne $pushItem) {
        $res = Get-Items -obj $pushItem
        $result2 += $res | ConvertTo-Json -Compress
      }
      else {
        $res = Get-Items -obj $jsonObject
        $result2 += $res | ConvertTo-Json -Compress
      }
    }
  }
  # $result += "`a"
  $result2 += "`a"
  Write-Host -NoNewLine $result2
}

function Set-MappedKeyHandlers {
  # Terminal suggest - always on keybindings
  Set-PSReadLineKeyHandler -Chord 'Ctrl+b' -ScriptBlock {
    Send-Completions
  }
}

# Register key handlers if PSReadLine is available
if (Get-Module -Name PSReadLine) {
  Set-MappedKeyHandlers
}
else {
  Write-Host "PsReadline was disabled. Shell Completion was not enabled."
}
@cereschen commented on GitHub (Dec 23, 2023): I have implemented the most basic fig like automatic completion, git.json is generated by the npm package @ withfig/autocomplete/build/git ```ts import * as fig from '@withfig/autocomplete/build/git' import { writeFileSync } from 'fs' writeFileSync('./git.json',JSON.stringify(fig.default)) ``` Note that I changed the shortcut key to ctrl+b ```powershell $directory = (Split-Path -Parent $PROFILE) $jsonFilePath = Join-Path -Path $directory -ChildPath 'Completions/git.json' $jsonContent = Get-Content -Raw -Path $jsonFilePath $jsonObject = $jsonContent | ConvertFrom-Json function Get-Items { param ( $obj ) $array = @() $mergedArray = $obj.subcommands + $obj.options $mergedArray | ForEach-Object { $name = $_.name $CompletionText = $_.name if ($_.name.GetType().BaseType.Name -eq "Array") { $name = $name -join " " $CompletionText = $_.name[0] } $description = $_.description $newObject = New-Object PSObject -Property @{ CompletionText = $CompletionText ListItemText = $name + " " + $description ResultType = 2 ToolTip = $description } $array += $newObject } return $array } function Send-Completions { $commandLine = "" $cursorIndex = 0 [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$commandLine, [ref]$cursorIndex) $completionPrefix = $commandLine $result2 = "`e]633;Completions" # $result = "`e]633;Completions" if ($completionPrefix.Length -gt 0) { $completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex if ($null -ne $completions.CompletionMatches) { # $result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);" # $result += $completions.CompletionMatches | ConvertTo-Json -Compress $result2 += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);" $subStr = $completionPrefix.Substring(0, $cursorIndex) $strArray = $subStr -split '\s+' $pushItem = $jsonObject.subcommands | Where-Object { $_.name -eq $strArray[1] } if ($null -ne $pushItem) { $res = Get-Items -obj $pushItem $result2 += $res | ConvertTo-Json -Compress } else { $res = Get-Items -obj $jsonObject $result2 += $res | ConvertTo-Json -Compress } } } # $result += "`a" $result2 += "`a" Write-Host -NoNewLine $result2 } function Set-MappedKeyHandlers { # Terminal suggest - always on keybindings Set-PSReadLineKeyHandler -Chord 'Ctrl+b' -ScriptBlock { Send-Completions } } # Register key handlers if PSReadLine is available if (Get-Module -Name PSReadLine) { Set-MappedKeyHandlers } else { Write-Host "PsReadline was disabled. Shell Completion was not enabled." } ```
Author
Owner

@rsteube commented on GitHub (Dec 23, 2023):

@cereschen have a look at microsoft/inshellisense.
With https://github.com/microsoft/inshellisense/pull/78 you can invoke the fig completions with inshellisense complete 'command args...'.
I've got a bridge for it at carapace-bridge as well which will be include in the next release of carapace-bin.

Things to note though:

Inshellisense uses a lexer to split the command which which is very basic.
E.g. at the moment it can't handle spaces, redirects, quotes, and so on.
The fig completions got quite a lot of issues as well.
So a lot of things don't work yet (and won't for quite a long time).

@rsteube commented on GitHub (Dec 23, 2023): @cereschen have a look at [microsoft/inshellisense](https://github.com/microsoft/inshellisense). With https://github.com/microsoft/inshellisense/pull/78 you can invoke the fig completions with `inshellisense complete 'command args...'`. I've got a bridge for it at [carapace-bridge](https://github.com/rsteube/carapace-bridge) as well which will be include in the next release of [carapace-bin](https://github.com/rsteube/carapace-bin). Things to note though: Inshellisense uses a lexer to split the command which which is **very** basic. E.g. at the moment it can't handle spaces, redirects, quotes, and so on. The fig completions got quite a lot of issues as well. So a lot of things don't work yet (and won't for quite a long time).
Author
Owner

@cereschen commented on GitHub (Dec 24, 2023):

@cereschen看看microsoft/inshellisense。 使用microsoft/inshellisense#78,您可以使用 调用无花果补全inshellisense complete 'command args...'我在carapace-bridge 上也有一个桥,它将包含在下一版本的carapace-bin中。

但需要注意的事项:

Inshellisense 使用词法分析器来拆分命令,这是非常基本的。 例如,目前它无法处理空格、重定向、引号等。 无花果的完成也遇到了很多问题。 所以很多事情还不起作用(而且在很长一段时间内都不起作用)。

I successfully used is today, but it took me too much time to call is using Invoke Expression. Perhaps there is a better way, as I am not proficient in Powershell

This seems to be an issue with IS, as it will take some time for it to end..

@cereschen commented on GitHub (Dec 24, 2023): > @cereschen看看[microsoft/inshellisense](https://github.com/microsoft/inshellisense)。 使用[microsoft/inshellisense#78,](https://github.com/microsoft/inshellisense/pull/78)您可以使用 调用无花果补全`inshellisense complete 'command args...'`。[我在carapace-bridge](https://github.com/rsteube/carapace-bridge) 上也有一个桥,它将包含在下一版本的[carapace-bin](https://github.com/rsteube/carapace-bin)中。[](https://github.com/rsteube/carapace-bridge)[](https://github.com/rsteube/carapace-bin) > > 但需要注意的事项: > > Inshellisense 使用词法分析器来拆分命令,这是**非常**基本的。 例如,目前它无法处理空格、重定向、引号等。 无花果的完成也遇到了很多问题。 所以很多事情还不起作用(而且在很长一段时间内都不起作用)。 I successfully used is today, but it took me too much time to call is using Invoke Expression. Perhaps there is a better way, as I am not proficient in Powershell This seems to be an issue with IS, as it will take some time for it to end..
Author
Owner

@Welding-Torch commented on GitHub (Feb 28, 2024):

I just started using Warp for WSL and it feels like it's lightyears ahead of this stuff. I think it would be great if Windows Terminal took some notes from it, especially on this feature request that's been open since 2019.

Also mentioned earlier in this thread by: @just1a-person in 2021 and @orcmid.

@Welding-Torch commented on GitHub (Feb 28, 2024): I just started using Warp for WSL and it feels like it's lightyears ahead of this stuff. I think it would be great if Windows Terminal took some notes from it, especially on this feature request that's been open _since 2019_. Also mentioned earlier in this thread by: @just1a-person in 2021 and @orcmid.
Author
Owner

@Jaykul commented on GitHub (Sep 10, 2025):

For what it's worth, after playing with the current preview bits ....

If the pretty terminal GUI gets the same information as the PowerShell TUI but just shows less of it, I don't think just the UI is going to win me over.

I need that menu to be wider, and I need some sort of support for that extra tool-tip text like what's in https://github.com/microsoft/terminal/issues/3121#issuecomment-1739900204 or in any of the default PowerShell ctrl+space completions for command names, where when you highlight one of the options you get a syntax block:

Image

Otherwise, I'm trading off the TUI for GUI but loosing information...

Obviously the risk here is that there's a little bit of a feature race going on when it comes to in-terminal help/completion/menus/etc., so there's every chance that as soon as you add support for some extra text, someone starts adding whole doc pages in a fzf style three-pane thing, or ... I don't know what ;-)

I still feel like this completion needs to at least be able to show the current information PowerShell feeds it ;)

@Jaykul commented on GitHub (Sep 10, 2025): For what it's worth, after playing with the current preview bits .... If the pretty terminal GUI gets the same information as the PowerShell TUI but just shows _less_ of it, I don't think just the UI is going to win me over. I need that menu to be wider, and I need some sort of support for that extra tool-tip text like what's in https://github.com/microsoft/terminal/issues/3121#issuecomment-1739900204 or in any of the default PowerShell ctrl+space completions for command names, where when you highlight one of the options you get a syntax block: <img width="1086" height="331" alt="Image" src="https://github.com/user-attachments/assets/a057a7fe-3769-4c95-bac6-9b65acb47b25" /> Otherwise, I'm trading off the TUI for GUI but _loosing information_... Obviously the risk here is that there's a little bit of a feature race going on when it comes to in-terminal help/completion/menus/etc., so there's every chance that as soon as you add support for some extra text, someone starts adding whole doc pages in a fzf style three-pane thing, or ... I don't know what ;-) I still feel like this completion needs to at least be able to show the _current_ information PowerShell feeds it ;)
Author
Owner

@DHowett commented on GitHub (Sep 10, 2025):

I still feel like this completion needs to at least be able to show the current information PowerShell feeds it ;)

weeeelll so far it feeds it nothing. that's somewhat what this deliverable is tracking: a protocol using-which PowerShell can feed it. :)

@DHowett commented on GitHub (Sep 10, 2025): > I still feel like this completion needs to at least be able to show the current information PowerShell feeds it ;) weeeelll so far it feeds it _nothing_. that's somewhat what this deliverable is tracking: a protocol using-which PowerShell _can_ feed it. :)
Author
Owner

@Tyriar commented on GitHub (Sep 10, 2025):

FWIW I ripped the pwsh session based completions out of VS Code in favor of the generic fig ones and LSP-based completions. At least the way we did it, feeding completions through the pty as the transport mechanism ended up locking up the terminal too much since it's the only pipe for I/O.

@Tyriar commented on GitHub (Sep 10, 2025): FWIW I ripped the pwsh session based completions out of VS Code in favor of the generic fig ones and LSP-based completions. At least the way we did it, feeding completions through the pty as the transport mechanism ended up locking up the terminal too much since it's the only pipe for I/O.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4348