Improve your PowerShell experience

Daniel MarczinDaniel Marczin
3 min read

Completions

Command completion is somewhat lackluster by default in PowerShell. Most of the built-in functions have tab-completion support, but for those of us socialized on better different shells, it might be a bit unusual at first. Out of the box, TAB invokes the tab completion for files and cmdlets with subsequent presses cycling through the available suggestions. Pressing Ctrl+Space provides a selection, similar to what ZSH offers for TAB presses.

You can remap these, if you don't want to bother re-learning them. First, let's open your profile.

code $PROFILE # just use your favourite editor

Then add the following line(s), setting the keys to whatever you're accustomed to:

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadlineKeyHandler -Key Shift+Tab -Function TabCompleteNext

To list all the shortcuts with descriptions, just use the command Get-PSReadLineKeyHandler

Go the extra mile

You can also install the latest version of PSReadLine, which is responsible for your completions, by running:

Install-Module -Name PSReadLine

The latest versions utilize the command history and various plugins for better completions. One of these plugins is CompletionPredictor, which can be installed just like we did with PSReadLine, and provides IntelliSense-like suggestion. You can toggle between the default and IntelliSense recommendations by pressing F2.

Install-Module -Name CompletionPredictor

In PWSH you can press F1 after entering a command to see its man-page.

Just use Bash? 👀

While I personally didn't have much luck with this tool, if you really need those completions for that one program that you use all the time (provided it has completions defined for bash), you might opt to try your luck with PS bash completions. This module acts as a bridge between bash and PowerShell, providing you with completions (with some limitations).

Make things pretty

Install Oh My Posh (á la Oh My ZSH), available on Windows, Linux and macOS. Just follow the instructions in their docs.

# Windows
winget install JanDeDobbeleer.OhMyPosh -s winget

# macOS & Linux
brew install jandedobbeleer/oh-my-posh/oh-my-posh

Then install a NerdFont, to display some fancy glyphs, by running:

sudo oh-my-posh font install
# or to run it without elevation use: --user

..and don't forget to configure your terminal to actually use the font(s) that you've just installed.

Next, configure a theme that you like. You can just run Get-PoshThemes which displays all the available themes, and even tells you how set one permanently.

Use git shorthands

You can use the same git aliases that you do in Oh My Zsh by installing the module powershell-git-aliases. If you are not familiar with them, Oh My ZSH provides a full list on their GitHub.

Just run the usual command to install it and add the module to your profile.

Install-Module git-aliases -Scope CurrentUser -AllowClobber

# then add this to your $PROFILE, and restart your terminal:

Import-Module git-aliases -DisableNameChecking

There it is! Now you can use your gcos, gpras and ggfls to your heart's content.

10
Subscribe to my newsletter

Read articles from Daniel Marczin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Daniel Marczin
Daniel Marczin

Using hashnode to syndicate my blogposts. If you want to read the latest posts, with my own design, visit https://marczin.dev/