PSCompletions (psc)
The content of this page is from the project README, please refer to the project README!
Introduce
Star ⭐️ or Donate 💰 if you like it!
Introduce
TIP
- PowerShell(pwsh): A cross-platform PowerShell (Core). Start it by running
pwsh/pwsh.exe. - Windows PowerShell: A PowerShell (Desktop) which is built-in on Windows system. Start it by running
powershell/powershell.exe. - They can both use
PSCompletions, but PowerShell(pwsh) is more recommended.
A completion manager for better and simpler use completions in PowerShell.
- More powerful completion menu.
- Manage completions together.
- Sort completion items dynamically by frequency of use.
- Switch between languages(
en-US,zh-CN,...) freely. - Combined with argc-completions.
Demo

What's new
- See the Changelog for details.
FAQ
- See the FAQ.
Contribution
- See the Contribution Guide for details.
How to install
Install module:
Import module:
powershellImport-Module PSCompletions- Add it to your
$Profileto make it permanent by running the following command.powershell"Import-Module PSCompletions" >> $Profile - Note: Recommend add
Import-Module PSCompletionsearly in$Profileto avoid the encoding issue.
- Add it to your
How to uninstall
Uninstall-Module PSCompletionsHow to use
TIP
- Available Completions.
- If it doesn't include the completion you want, you can submit an issue.
- You can also combined with argc-completions.
Take git as an example.
- Add completion:
psc add git - Then you can enter
git, pressSpaceandTabkey to get command completion. - For more usages on
psc, you just need to enterpsc, pressSpaceandTabkey, and you will get all usages ofpscby reading the completion tip.
Tips
About the completion trigger key
PSCompletionsuses theTabkey by default.- You can set it by running
psc menu config trigger_key <key>.
WARNING
- If you need
Set-PSReadLineKeyHandler -Key <key> -Function <MenuComplete|Complete> - Please add it before
Import-Module PSCompletions
About completion menu
In addition to the built-in completion menu of
PowerShell,PSCompletionsmodule also provides a more powerful completion menu.- Setting:
psc menu config enable_menu 1(Default:1) - Its related behaviors can be controlled via other configuration items in
psc menu config.
- Setting:
It is only available in Windows, because PowerShell in Linux/MacOS does not implement the relevant methods.
Some key bindings in the module's completion menu.
Apply the selected completion item:
Enter/Space- You can also use
Tabwhen there's only one completion.
- You can also use
Delete filter characters:
BackspaceExit the completion menu:
Esc/Ctrl + c- You can also use
Backspacewhen there're no characters in the filter area.
- You can also use
Select completion item:
Select previous item Select next item UpDownLeftRightShift + TabTabCtrl + uCtrl + dCtrl + pCtrl + n
All configurations of it, you can trigger completion by running
psc menu, then learn about them by the completion tip.- For configured values,
1meanstrueand0meansfalse. (It applies to all configurations ofPSCompletions) - Some common menu behaviors:
- Auto-apply when there's only one completion item:
psc menu config enable_enter_when_single 1 - Use prefix matching for filtering:
psc menu config enable_prefix_match_in_filter 1- If it is
0, fuzzy matching is used, and the*and?wildcards are supported.
- If it is
- ...
- Auto-apply when there's only one completion item:
- For configured values,
About menu enhance
- Setting:
psc menu config enable_menu_enhance 1(Default:1) - Now,
PSCompletionshas two completion implementations.- Set-PSReadLineKeyHandler
- It's used by default.
- Requires:
enable_menuandenable_menu_enhanceboth set to1.
- Requires:
- It no longer needs to loop through registering Register-ArgumentCompleter for all completions, which theoretically makes loading faster.
- It use TabExpansion2 to manage completions globally, not limited to those added by
psc add.- Path completion such as
cd/.\/..\/~\/... - Build-in commands such as
Get-*/Set-*/New-*/... - Completion registered by Register-ArgumentCompleter
- Combined with argc-completions.
- Completion registered by cli or module.
- ...
- Path completion such as
- It's used by default.
- Register-ArgumentCompleter
- You can use it by running
psc menu config enable_menu_enhance 0. - It only works for completions added by
psc add.
- You can use it by running
- Set-PSReadLineKeyHandler
About option completion
Optional Completions: some command completions that like-*, such as--globalingit config --global.- You should use option completion first.
- Taking
gitas an example, if you want to entergit config user.name --global xxx, you should use--globalcompletion first, and then useuser.name, and then enter the namexxx. - For options ending with
=, if there's completion definition, you can directly press theTabkey to get the completions.
About special symbols
TIP
- Due to changes in Windows Terminal, 😄🤔😎 cannot be displayed properly in the completion menu, so they will be replaced.
- Related issue: https://github.com/microsoft/terminal/issues/18242
- The changes are as follows:
😄=>~🤔=>?😎=>!
Special symbols after the completion item are used to let you know in advance if completions are available before you press the
Tabkey.- They only exist in completions added by
psc add. - They can be customized by running
psc menu symbol <type> <symbol> - For example, you can replace them with empty strings to hide them.
psc menu symbol SpaceTab ""psc menu symbol OptionTab ""psc menu symbol WriteSpaceTab ""
- They only exist in completions added by
~,?,!: If there are multiple, you can choose the effect of one of them.~: It means that after you apply it, you can pressTabkey to continue to get completions.?: It means that after you apply the (General) option completion, you can pressTabkey to continue to get current completion items in completion menu.!: It means that after you apply the (General) option completion, you can press enter a string, then pressTabkey to continue to get current completion items in completion menu.- If the string has spaces, please use
"or'to wrap it. e.g."test content" - If there's also
~, it means that there's some preset completions, you can pressTabkey to continue to get them without entering a string.
- If the string has spaces, please use
About completion tip
The completion tip is only a helper, you can also disable the tip by running
psc menu config enable_tip 0- It's enabled by default:
psc menu config enable_tip 1 - You can also disable the tip for a specific completion, such as
git.psc completion git enable_tip 0
- It's enabled by default:
General structure of the completion tip:
Usage+Description+ExampletxtU: install|add [-g|-u] [options] <app> This is a description of the command. E: install xxx add -g xxxExample Analysis:
- Usage: Begin with
U:- command name:
install - command alias:
add - required parameters:
<app>appis a simple summary of the parameters.
- optional parameters:
-g-u[options]: Some options.
- command name:
- Description: The description of the command.
- Example: Begin with
E:
- Usage: Begin with
About language
Global language: Default to the language of current system.- You can show it by running
psc config language. - You can change it by running
psc config language zh-CN.
- You can show it by running
Completion language: The language set for the specified completion.- e.g.
psc completion git language en-US.
- e.g.
Available language: In the completionconfig.jsonfile, there is alanguageattribute whose value is a list of available languages.
Determine language
- If there is
Completion language,use it. If not, useGlobal language. - Determine the final language:
- Determine whether the value of the first step exists in
Available language. - If it exists, use it.
- If not, use the first of the
Available language. (It's usuallyen-US)
- Determine whether the value of the first step exists in
About path completion
- Take
gitfor example, when enteringgit add, pressing theSpaceandTabkeys, path completion will not be triggered, only completion provided by the module will be triggered. - If you want to trigger path completion, you need to enter a content which matches
^(?:\.\.?|~)?(?:[/\\]).*. - e.g.
- Please enter
./or.\and pressTabkey to get path completion for the subdirectory or file. - Please enter
../or..\and pressTabkey to get path completion for the parent directory or file. - Please enter
/or\and pressTabkey to get path completion for the sibling directory. - More examples:
~//../../...
- Please enter
- So you can enter
git add ./and then pressTabkey to get the path completion.
Acknowledgements
- PS-GuiCompletion: The completion menu provided by the module is inspired by it.