It is possible to make autocompletion in Powershell work like in bash?

I love Powershell, but coming from a Linux background there is a few things that is really bugging me. Like for example how the default auto completion works.

For example: Get-PS expands to "Get-PSBreakpoint" which is the first matching command. In bash if there is only one command matching bash will expand to the matching command. If there is several hitting tab once does nothing, double tapping tab will show a list of matching commands but not expanding. Is there a way to make Powershell behave like this?

And one other thing, if i have written one line, and moves the marker back to an earlier command (marker is where the ^ is):

"Get-PSS^ | Remove-PSSession" auto completes to "Get-PSSession^", removing all trailing commands. In bash the trailing commands would still be there unaffected. Is there a way to make Powershell not remove the trailing commands when auto completing?

A bonus would be to get CTRL+L to clear the screen. CTRL+A to go to the beginning of the line, and CTRL+E to go to the end of the line.


Solution 1:

Check out PSReadline.

From the article:

This module replaces the command line editing experience in PowerShell.exe. It provides:

  • Syntax coloring
  • Simple syntax error notification
  • A good multi-line experience (both editing and history)
  • Customizable key bindings
  • Cmd and emacs modes (neither are fully implemented yet, but both are usable)
  • Many configuration options
  • Bash style completion (optional in Cmd mode, default in Emacs mode)
  • Bash/zsh style interactive history search (CTRL-R)
  • Emacs yank/kill ring
  • PowerShell token based "word" movement and kill
  • Undo/redo
  • Automatic saving of history, including sharing history across live sessions
  • "Menu" completion (somewhat like Intellisense, select completion with arrows) via Ctrl+Space

I use it daily!

Solution 2:

Maybe you should have a look at Powertab, a customizable PowerShell Tab expansion.

Solution 3:

hi peter just press F8 for something like speedsearch. It completes with the commands that you run previously that start with what you have in the line. The problem with the deletion of the trailing is annoying, I write a suggestion in Connect regarding the same issue. In the main time you could use Powershell ISE, that behave a little better(don't delete the trailing characters).

Solution 4:

The old command.exe subsystem is still involved in PowerShell, and forces a lot of unpleasant behaviors. But as of PowerShell v3, the GUI (PowerShell ISE) is now usable, and it includes a much more modern completion experience + colorization.

enter image description here

Solution 5:

PowerShell uses the same console features as the venerable Command Prompt; so you have the usual Home/End, and:

  • F3 to bring up the previous command
  • F1 to copy a single character from the previous command
  • F7 popup history window

...but there's no facility to show all possible completions, as far as I know.