Setup PowerShell Autocomplete
Setup PowerShell Autocomplete
Enable Linux-style shell autocompletion in PowerShell using the PSReadLine module.
Installation
1
Install-Module PSReadLine
Configuration
Edit your PowerShell profile:
1
notepad $PROFILE
Add the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Check if PSReadLine module is available, if not, install it
if (-not (Get-Module -ListAvailable -Name PSReadLine)) {
Install-Module -Name PSReadLine -Force -Scope CurrentUser
}
# Check if PSReadLine is loaded, if not, import it
if (-not (Get-Module -Name PSReadLine)) {
Import-Module PSReadLine
}
# Shows navigable menu of all options when hitting Tab
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
# Autocomplete for Arrow keys
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineOption -ShowToolTips
Set-PSReadLineOption -PredictionSource History
This makes your terminal start slightly slower, but it’s worth it.
References
This post is licensed under CC BY 4.0 by the author.