Guida per configurare PowerShell 7 con autocompletamento, Oh My Posh e icone
Installa PowerShell 7
winget install Microsoft.PowerShell
Chiudi e riapri Windows Terminal. Ora vedrai “PowerShell” come nuovo profilo.
Abilita esecuzione script
Apri PowerShell 7 come amministratore ed esegui:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Conferma con Y quando richiesto.
Installa Oh My Posh
winget install JanDeDobbeleer.OhMyPosh
Testa che funzioni:
oh-my-posh init pwsh | Invoke-Expression
Installa un Nerd Font
Necessario per visualizzare le icone nel prompt:
oh-my-posh font install
Scegli CaskaydiaCove o FiraCode.
ℹ️ Configurazione Font
Vai in Windows Terminal → Settings → Profiles → Defaults → Appearance → Font face e seleziona il font installato (es. “CaskaydiaCove Nerd Font”).
Installa Terminal-Icons
Install-Module -Name Terminal-Icons -Repository PSGallery -Force
Crea il file $PROFILE
Questo file viene eseguito ad ogni avvio di PowerShell:
New-Item -Path $PROFILE -Type File -Force
notepad $PROFILE
Contenuto del $PROFILE
# Oh My Posh
oh-my-posh init pwsh | Invoke-Expression
# PSReadLine - Autocompletamento
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
# Terminal Icons
Import-Module Terminal-Icons
Copia questo contenuto nel file e salva.
Imposta PowerShell 7 come default
In Windows Terminal: Settings → Startup → Default profile → seleziona “PowerShell”
In VS Code: Apri settings.json e aggiungi:
{
"terminal.integrated.defaultProfile.windows": "PowerShell"
}
Riavvia e verifica
Chiudi tutto e riapri Windows Terminal. Verifica con:
# Versione PowerShell (deve essere 7.x)
$PSVersionTable.PSVersion
# Versione PSReadLine (deve essere 2.2+)
Get-Module PSReadLine
⚠️ Troubleshooting
Se PSReadLine non supporta -PredictionSource, aggiornalo manualmente:
Install-Module PSReadLine -Force -SkipPublisherCheck Setup testato su Windows 11 con PowerShell 7