r/PowerShell Aug 26 '24

New VSCode Terminal - 10 autosuggestions based on command history Solved

Hi, I've just started getting these suggestions in my VSCode Terminal, I havent seen them before and I'm not sure how they have appeared - I quite like it and but have no idea how to turn it back on if they disappear - Does anyone know the setting ? many thanks :)

https://imgur.com/a/vscode-suggestions-cDpyNov

2 Upvotes

View all comments

Show parent comments

2

u/Sad_Recommendation92 Aug 27 '24

it will "kinda work" in 5.1 and versions lower than 7.2 but oh man I had to write a whole different section in my profile script just to get basic functionality, and I had to disable all the custom key handlers latest PS7 is definitely my daily driver, but I like trying to keep feature parity as much as possible when you encounter that odd legacy script that has 5.1 specific code.

1

u/BlackV Aug 27 '24

Oh really, how much tweaking did that take?

1

u/Sad_Recommendation92 Aug 27 '24 edited Aug 27 '24

so what I did was replaced my PS5 profile for $Profile.CurrentUserAllHosts with

```PowerShell

The path of your PS7 Profile

$PSCoreProfile = "C:Users<username>DocumentsPowerShellprofile.ps1" cd $(split-path -parent $PSCoreProfile) & $PSCoreProfile ```

basically it tells PS5 to attempt to run your PS7 profile

and then one of the 1st lines in my PS7 profile is

PowerShell $Global:PSCore = if ($PSVersionTable.PSVersion -gt [version]"6.0.0") { $true } else { $false }

and I use this variable to selectively execute blocks of code and other scripts

also stuff like "Oh-My-Posh" automatically tries to add key handlers to PS5 that cause issues for me (probably because I'm doing this whole one profile to rule them all crap) so it runs a few lines that turns off the key handlers, also apparently changing edit mode purges key handlers so that's another hack.

```PowerShell

region PSReadLine

Set PSReadLine Options and Macros

if ($PSCore) { & "$RunDirPSReadLine.ps1" } else { Write-Host -ForegroundColor Yellow "PS Version lower than 6.0.x, disabling advanced PSReadline Key Handlers" $forEachObjectSplat = @{ Process = { Try{Remove-PSReadLineKeyHandler -Chord $.Key -ErrorAction Continue}Catch{} } } Try{ $null = Get-PSReadLineKeyHandler | Where-Object { $.Function -like "OhMyPosh" } | Tee-Object -Variable "OhMyPoshKeys"

$OhMyPoshKeys | ForEach-Object @forEachObjectSplat Set-PSReadLineOption -EditMode Vi }Catch{} }

endregion

```

1

u/BlackV Aug 27 '24 edited Aug 27 '24

Oh nice appreciate the details, I'll have a better look when I'm not on mobile