Extend PowerShell’s command line with PSReadLine

PSReadLine

Let’s be frank: Microsoft’s command line environments are terrible. When we’re having to wait until Windows 10 to get proper Ctrl+C/ Ctrl+V copy/ paste support -- something which the GUI has had for as long as many PC users have been alive -- you know there’s a problem.

Moving to PowerShell doesn’t in itself improve the situation, but at least you get access to PSReadLine, an excellent PowerShell module which does a lot to improve the command line editor.

Downloading PSReadLine gives you the most control over how it’s installed, but if you just want to give it a quick try, PSGet offers the easiest route.

Enter this line at the PowerShell console (paste the URL into a browser if you’d like to check what it does):

(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex

Entering the next line installs PsReadLine:

install-module PsReadLine

This immediately gets you simple syntax highlighting. Type a command or paste in a sample script to see how it works.

Line editing now works more as you’d expect. Ctrl+A selects the full line, Ctrl+C copies it to the clipboard, Ctrl+V pastes clipboard text to the console. There’s even multiple undo/ redo via Ctrl+Z and Ctrl+Y.

There’s built-in syntax checking, with the prompt ">" turning red to indicate there’s a problem. This is particularly useful when you’re entering a complex multi-line function, and what’s more, if you spot the problem then you can now move your cursor from one line to another and directly edit what you see -- no need to start again.

Perhaps best of all, pressing Ctrl+Space launches an autocomplete-type feature which displays matching commands or parameters for your current line, and allows you to select what you need with the arrow keys.

There’s also an optional Emacs mode for even more power, and it’s all extremely customizable.

PSReadLine is available now for PowerShell 3/ Windows 7 and later.

6 Responses to Extend PowerShell’s command line with PSReadLine

© 1998-2024 BetaNews, Inc. All Rights Reserved. Privacy Policy - Cookie Policy.