Skip to content

Instantly share code, notes, and snippets.

@jgentes
Last active April 9, 2026 21:45
Show Gist options
  • Select an option

  • Save jgentes/534714b3b1ad239a31bc220918429ae5 to your computer and use it in GitHub Desktop.

Select an option

Save jgentes/534714b3b1ad239a31bc220918429ae5 to your computer and use it in GitHub Desktop.
powershell autocomplete
# 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