2

I was wondering if there was anyway to change the way the current powershell autocomplete works. I have been using bash and had changed them to offer a few features that I'd like in my powershell experience.

Currently powershell as I'm writing a command with a folder it will tab autocomplete and also cycle through my folders. This works how I like but one feature that I miss is using partial matching of a command and hitting the up key and it would find that command that matches the rest of what I do.

So Id write 'echo test' Then id write other commands and try 'ec' and tap up and 'echo test' would complete and not the last command I typed

Just wondering if there is anyway anyway to get this back?

2

One feature that I miss is using partial matching of a command and hitting up

You can use PSReadLine (A bash inspired readline implementation for PowerShell) for this:

PSReadLine

This module replaces the command line editing experience in PowerShell.exe for versions 3 and up. 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

...

To set your own custom keybindings, use the cmdlet Set-PSReadlineKeyHandler. For example, for a better history experience, try:

Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

With these bindings, up arrow/down arrow will work like PowerShell/cmd if the current command line is blank. If you've entered some text though, it will search the history for commands that start with the currently entered text.

Source PSReadLine

  • @James As per the source link put the bindings in C:\Users\[User]\Documents\WindowsPowerShell\profile.ps1. See the Readme – DavidPostill Apr 17 '17 at 16:52
  • Worked great! And works in my vs code shell as well with no problems. And yeah I figured out the profile thing right after I asked it. Similar to .bashrc – James Apr 17 '17 at 17:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.