Last active
April 9, 2026 21:45
-
-
Save jgentes/534714b3b1ad239a31bc220918429ae5 to your computer and use it in GitHub Desktop.
powershell autocomplete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # CurrentUserAllHosts — runs for every PowerShell 7 host (integrated terminal, VS Code/Cursor | |
| # PowerShell pane, Windows Terminal). Console-only host files can miss Cursor depending on host. | |
| $__prevProgress = $ProgressPreference | |
| $ProgressPreference = 'SilentlyContinue' | |
| try { | |
| # Load posh-git at startup so prompt + git tab completion work reliably (deferred import breaks that). | |
| if (Get-Module -ListAvailable -Name posh-git) { | |
| Import-Module posh-git | |
| } else { | |
| Write-Warning "posh-git is not installed; git prompt extras are disabled. Install: Install-Module posh-git -Scope CurrentUser -Force -AllowClobber" | |
| } | |
| if (-not (Get-Module -Name PSReadLine)) { | |
| Import-Module PSReadLine | |
| } | |
| # Predictions need a real VT-capable console (skip quietly in non-interactive / redirected) | |
| try { | |
| if ($host.UI.SupportsVirtualTerminal) { | |
| Set-PSReadLineOption -PredictionSource HistoryAndPlugin -PredictionViewStyle InlineView | |
| } | |
| } catch { | |
| # Older PSReadLine or restricted host | |
| } | |
| Set-PSReadLineOption -EditMode Windows | |
| Set-PSReadLineKeyHandler -Key Tab -Function Complete | |
| Set-PSReadLineKeyHandler -Key Shift+Tab -Function MenuComplete | |
| try { | |
| Set-PSReadLineKeyHandler -Key Alt+RightArrow -Function AcceptNextSuggestionWord | |
| } catch { | |
| # PSReadLine too old for this function | |
| } | |
| # Optional: jump to c:\dev for "plain" shells; keep the folder Cursor/VS Code started in (workspace). | |
| $editorTerminal = ( | |
| ($env:TERM_PROGRAM -eq 'vscode') -or | |
| ($null -ne $env:VSCODE_IPC_HOOK_CLI) -or | |
| ($null -ne $env:VSCODE_GIT_IPC_HANDLE) -or | |
| ($null -ne $env:CURSOR_CLI) -or | |
| ($null -ne $env:CURSOR_AGENT) | |
| ) | |
| if (-not $editorTerminal) { | |
| $here = (Get-Location).Path.TrimEnd('\') | |
| $userHome = $env:USERPROFILE.TrimEnd('\') | |
| $homeTrim = $HOME.TrimEnd('\') | |
| $winRoot = $env:SystemRoot.TrimEnd('\') | |
| $genericStart = ( | |
| ($here -match '^[A-Z]:$') -or | |
| ($here -ieq $userHome) -or | |
| ($here -ieq $homeTrim) -or | |
| ($here -ieq (Join-Path $env:SystemRoot 'System32')) -or | |
| ($here -ieq $winRoot) | |
| ) | |
| if ($genericStart) { | |
| Set-Location -Path 'c:\dev' | |
| } | |
| } | |
| } finally { | |
| $ProgressPreference = $__prevProgress | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment