Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Improve your PowerShell experience
Daniel Marczin
Daniel Marczin

Posted on • Originally published atmarczin.dev

Improve your PowerShell experience

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 onbetter 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.
PressingCtrl+Space provides a selection, similar to what ZSH offers forTAB 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
Enter fullscreen modeExit fullscreen mode

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

Set-PSReadlineKeyHandler-KeyTab-FunctionMenuCompleteSet-PSReadlineKeyHandler-KeyShift+Tab-FunctionTabCompleteNext
Enter fullscreen modeExit fullscreen mode

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

Go the extra mile

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

Install-Module-NamePSReadLine
Enter fullscreen modeExit fullscreen mode

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

Install-Module-NameCompletionPredictor
Enter fullscreen modeExit fullscreen mode

In PWSH you can pressF1 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 forthat one program that you use all the time (provided it has completions defined for bash),
you might opt to try your luck withPS 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 instructionsin their docs.

# WindowswingetinstallJanDeDobbeleer.OhMyPosh-s winget# macOS & Linuxbrewinstalljandedobbeleer/oh-my-posh/oh-my-posh
Enter fullscreen modeExit fullscreen mode

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

sudooh-my-posh fontinstall# or to run it without elevation use: --user
Enter fullscreen modeExit fullscreen mode

..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 runGet-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 modulepowershell-git-aliases.
If you are not familiar with them, Oh My ZSH provides a full liston their GitHub.

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

Install-Modulegit-aliases-ScopeCurrentUser-AllowClobber# then add this to your $PROFILE, and restart your terminal:Import-Modulegit-aliases-DisableNameChecking
Enter fullscreen modeExit fullscreen mode

There it is! Now you can use yourgcos,gpras andggfls to your heart's content.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp