Expanding Aliases with PSReadline

TLDR; Add this code to your $PROFILE, or paste it directly into the console to give it a test drive. Start typing aliases then press Ctrl+e to replace those aliases with the full command. The keybind does not persist upon exiting unless you add it to your $PROFILE.

Code: GitHub link

Example in action: Imgur link

I’m sure not many people were aware of this functionality so I thought I would share. Requires PSReadline (obviously) which is already installed by default in Win10, for Win7 you will need PS v5+ and this module if you don’t have it already.

Uses Set-PSReadlineKeyHandler to set the keybind. You can change which key you want by changing the Chord parameter in the $Params hash table, just make sure you don’t conflict with any other keys in use. You can check which keys are bound by running Get-PSReadlineKeyHandler -Bound.

Original code came from here https://github.com/lzybkr/PSReadLine/blob/master/PSReadLine/SamplePSReadLineProfile.ps1#L424 I slightly reformatted it and I fixed a minor issue where it would not work on the first command on a freshly opened PowerShell window.

The code from the final example in the .gif if you want to have some fun:

(Get-Alias).Name -join ';' | Set-Clipboard 

Paste back onto your line then press Ctrl+e

submitted by /u/nothingpersonalbro
[link] [comments]

Leave a Reply