-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Enhance shell autocompletion with a cool new user interface and shell completion protocol #3121
Comments
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 |
I think you can get inspired by Visual Studio's C# Interactive and PowerShell ISE. |
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.) |
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 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.) |
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!) |
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. |
I think the PowerShell team (or PSReadLine) and the Windows Terminal team can work together to make something like this happen. |
Footnotes
|
@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 |
@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 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. |
@zadjii-msft I have raised a bug: #16053 |
@rsteube how did you configure this? |
@jerkovicl Windows Terminal according to the wiki, the completions are custom. |
@rsteube yeah i have meant the color part and the command description |
I'm adding it to the 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 oh cool, thx for snippet:) |
It's on scoop and winget if you want to try it yourself. # ~/.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 thx, i installed and set it all up, it works:) |
## Summary of the Pull Request > ## Abstract > > Multiple related scenarios have come up where it would be beneficial to display > actionable UI to the user within the context of the active terminal itself. This > UI would be akin to the Intellisense UI in Visual Studio. It appears right where > the user is typing, and can help provide immediate content for the user, based > on some context. The "Suggestions UI" is this new ephemeral UI within the > Windows Terminal that can display different types of actions, from different > sources. > ## Detailed Description of the Pull Request / Additional comments _\*<sup>\*</sup><sub>\*</sub> read the spec <sub>\*</sub><sup>\*</sup>\*_ Similar to #14792, a lot of this code is written. This stuff isn't checked in though, so I'm presenting formally before I start yeeting PRs out there. ## PR Checklist - [x] This is a spec for #1595. It also references: * #3121 * #10436 * #12927 * #12863
Is there any way to have the completion menu support typing to narrow down the list? |
FYI thanks to some contributions from @cpendery you can once again enable suggest in VS Code's terminal ( 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 microsoft/vscode#154662 |
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 have a look at microsoft/inshellisense. Things to note though: Inshellisense uses a lexer to split the command which which is very basic. |
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.. |
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. |
This adds a `"description"` property to actions. Notably, the shell completion protocol (#3121) will now also populate that. The suggestions UI can then use those descriptions to display an additional tooltip with that information. TeachingTip was kinda an abject disaster last time I tried this, so this _isn't_ a TeachingTip. It's literally a text block. xlinks: * #13000 * #15845 * #14939 - the last abandoned attempt at this
This specs out a lot of plans for snippets. We've already got these in the sxnui as "tasks", but we can do so very much more. This spec is a few years old now, but it's time for it to get promoted out of my draft branch. References: * #1595 * #7039 * #3121 * #10436 * #12927 * #12857 * #5790 * #15845 --------- Co-authored-by: Dustin L. Howett <duhowett@microsoft.com>
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.
The text was updated successfully, but these errors were encountered: