Skip to content

Instantly share code, notes, and snippets.

@dipu-bd
Created June 2, 2021 01:55
Show Gist options
  • Save dipu-bd/9c31b5b02410a182824bd896f5a26a49 to your computer and use it in GitHub Desktop.
Save dipu-bd/9c31b5b02410a182824bd896f5a26a49 to your computer and use it in GitHub Desktop.
PowerShell Config for autocompletion and persisting history
# Shows navigable menu of all options when hitting Tab
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# Autocompletion for arrow keys
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
#Save Command History
$HistoryPath = 'C:\Users\Dipu\Documents\WindowsPowerShell\History'
If (Test-Path "${HistoryPath}\History.csv") {
Import-Csv "${HistoryPath}\History.csv" | Add-History
} ElseIf (!(Test-Path $HistoryPath)) {
New-Item -Path $HistoryPath -ItemType Directory
}
Register-EngineEvent -SourceIdentifier powershell.exiting -SupportEvent -Action {Get-History | Select-Object -Last 10000 | Export-Csv -Path "${HistoryPath}\History.csv"}
@dipu-bd
Copy link
Author

dipu-bd commented Jun 2, 2021

Create new profile if not exists:

if (!(Test-Path -Path $PROFILE.CurrentUserAllHosts)) {
   New-Item -ItemType File -Path $PROFILE.CurrentUserAllHosts -Force
}

Open profile to edit:

ii $PROFILE.CurrentUserAllHosts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment