Skip to content

Instantly share code, notes, and snippets.

@mike-clark-8192
Created May 16, 2024 05:40
Show Gist options
  • Save mike-clark-8192/dab35e2d070d7ff6c0f2ee96da3756c5 to your computer and use it in GitHub Desktop.
Save mike-clark-8192/dab35e2d070d7ff6c0f2ee96da3756c5 to your computer and use it in GitHub Desktop.
PowerShell "reload $profile" "alias" via PSReadLine
function _PSReadLineRewriteCommand {
param($key)
$commandLine = ''
$cursorIndex = 0
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$commandLine, [ref]$cursorIndex)
if ($commandLine -eq 'prof' -or $commandLine -eq 'profile') {
[Microsoft.PowerShell.PSConsoleReadLine]::Delete(0, $commandLine.Length)
[Microsoft.PowerShell.PSConsoleReadLine]::Insert('. $profile')
}
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
}
Set-PSReadLineKeyHandler -Key Enter -ScriptBlock { _PSReadLineRewriteCommand }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment