PSCompletions (psc)
The content of this page is from the project README, please refer to the project README!
Introduce
TIP
PowerShell(pwsh)
: A cross-platform PowerShell. Start it by runningpwsh
/pwsh.exe
.Windows PowerShell
: A PowerShell which is built-in on Windows system. Start it by runningpowershell
/powershell.exe
.- They can both use
PSCompletions
, butPowerShell(pwsh)
is more recommended.
- A completion manager in
PowerShell
for better and simpler use completions. - Manage completions together.
- Switch between languages(
en-US
,zh-CN
,...) freely. - Sort completion items dynamically by frequency of use.
- More powerful completion menu.
- Combined with argc-completions.
What's new
- See the CHANGELOG for details.
FAQ
- See the FAQ.
How to install
WARNING
PowerShell(pwsh)
: Don't add-Scope AllUsers
unless you're sure you'll always use administrator permissions.Windows PowerShell
: Don't omit-Scope CurrentUser
unless you're sure you'll always use administrator permissions.
Start
PowerShell
.Install module:
Normal:
powershellInstall-Module PSCompletions
Install silently:
powershellInstall-Module PSCompletions -Repository PSGallery -Force
Use Scoop
shellscoop bucket add abgox-bucket https://github.com/abgox/abgox-bucket
shellscoop install abgox-bucket/PSCompletions
Import module:
powershellImport-Module PSCompletions
- Add it to your
$PROFILE
to make it permanent by running the following command.powershellecho "Import-Module PSCompletions" >> $PROFILE
- Note: Recommend add
Import-Module PSCompletions
early in$PROFILE
to void the encoding issue. - About the completion trigger key.
- Add it to your
How to uninstall
- Start
PowerShell
. - Uninstall module:powershell
Uninstall-Module PSCompletions
How 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.
psc add git
- Then you can enter
git
, pressSpace
andTab
key to get command completion. - For more usages on
psc
, you just need to enterpsc
, pressSpace
andTab
key, and you will get all usages ofpsc
by reading the completion tip.
Demo
Contribution
- See the CONTRIBUTING for details.
Tips
About the completion trigger key
PSCompletions
uses theTab
key by default.- You can set it by running
psc menu config trigger_key <key>
.
WARNING
If you need to set
Set-PSReadLineKeyHandler -Key <key> -Function <MenuComplete|Complete>
Please add it before
Import-Module PSCompletions
Example:
powershellSet-PSReadLineKeyHandler -Key Tab -Function MenuComplete Import-Module PSCompletions
About completion update
- When
PSCompletions
module is imported after startingPowerShell
, it will start a background job to check for the completion status of the remote repository. - After getting the update,
PSCompletions
will show the latest status of the completions in the next time.
About option completion
Optional Completions
: some command completions that like-*
, such as--global
ingit config --global
.- You should use option completion first.
- Taking
git
as an example, if you want to entergit config user.name --global xxx
, you should use--global
completion first, and then useuser.name
, and then enter the namexxx
. - For options ending with
=
, if there's completion definition, you can directly press theTab
key to get the completions.
About completion menu
In addition to the built-in completion menu of
PowerShell
,PSCompletions
module also provides a more powerful completion menu.- Setting:
psc menu config enable_menu 1
(Default:1
)
- Setting:
The module's completion menu is based on PS-GuiCompletion realization idea, thanks!
Available Windows environment:
PowerShell
Windows PowerShell
- Due to rendering problems of
Windows PowerShell
, the border style of the completion menu cannot be customized.- If you need to customize it, use
PowerShell
.
- If you need to customize it, use
- Due to rendering problems of
Some keys in the module's completion menu.
Apply the selected completion item:
Enter
/Space
- You can also use
Tab
when there's only one completion.
- You can also use
Delete filter characters:
Backspace
Exit the completion menu:
Esc
/Ctrl + c
- You can also use
Backspace
when there're no characters in the filter area.
- You can also use
Select completion item:
Select previous item Select next item Up
Down
Left
Right
Shift + Tab
Tab
Ctrl + u
Ctrl + d
Ctrl + p
Ctrl + n
All configurations of it, you can trigger completion by running
psc menu
, then learn about them by the completion tip.- For configured values,
1
meanstrue
and0
meansfalse
. (It applies to all configurations ofPSCompletions
)
- For configured values,
About menu enhance
Setting:
psc menu config enable_menu_enhance 1
(Default:1
)Now,
PSCompletions
has two completion implementations.Set-PSReadLineKeyHandler
- It's used by default.
- Requires:
enable_menu
andenable_menu_enhance
both 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 bypsc add
.- For example:
- Path completion such as
cd
/.\
/..\
/~\
/... inPowerShell
. - Build-in commands such as
Get-*
/Set-*
/New-*
/... inPowerShell
. - Completion registered by
Register-ArgumentCompleter
- Combined with argc-completions.
- Completion registered by cli or module.
- ...
- Path completion such as
- For example:
- 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
. - Other completions are controlled by
Set-PSReadLineKeyHandler -Key <key> -Function <MenuComplete|Complete>
.
- You can use it by running
About special symbols
TIP
- Due to future changes in Windows Terminal, 😄🤔😎 will not be displayed properly in the completion menu, so these three default special symbols will change.
- 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
Tab
key.- They only exist in completions added by
psc add
. - You can hide them by replacing them with the empty string.
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.- Define them:
Normal Completions
: Sub-commands. Such asadd
/pull
/push
/commit
/... ingit
.Optional Completions
: Optional parameters. Such as-g
/-u
/... ingit add
.General Optional Completions
: General optional parameters that can be used with any command. Such as--help
/... ingit
.Current Completions
: Current completion items in completion menu.
»
: It means that after you apply it, you can pressSpace
andTab
key to continue to get completions.- It can be customized by running
psc menu symbol SpaceTab <symbol>
- It can be customized by running
?
: It means that after you apply it (Optional Completions
orGeneral Optional Completions
), you can pressSpace
andTab
key to continue to getCurrent Completions
.- It can be customized by running
psc menu symbol OptionTab <symbol>
- It can be customized by running
!
: It means that after you apply it (Optional Completions
orGeneral Optional Completions
), you can pressSpace
and enter a string, then pressSpace
andTab
key to continue to get completions.- If the string has Spaces, Please use
"
(quote) or'
(single quote) to wrap it. e.g."test content"
- If there's also
»
, it means that there's some preset completions, you can pressSpace
andTab
key to continue to get them without entering a string. - It can be customized by running
psc menu symbol WriteSpaceTab <symbol>
- If the string has Spaces, Please use
- All completions can be triggered by pressing the
Tab
key after entering a part.
- Define them:
About completion tip
The completion tip is only a helper, you can also disable the tip by running
psc menu config enable_tip 0
- To enable the completion tip, run
psc menu config enable_tip 1
. - You can also disable the tip for a specific completion, such as
psc
.psc completion psc enable_tip 0
- To enable the completion tip, run
General structure of the completion tip:
Usage
+Description
+Example
txtU: install|add [-g|-u] [options] <app> This is a description of the command. E: install xxx add -g xxx
Example Analysis:
- Usage: Begin with
U:
- command name:
install
- command alias:
add
- required parameters:
<app>
app
is 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.json
file, there is alanguage
attribute whose value is a list of available languages.
Determine language
- Get the specified language:
- If there is
Completion language
,use it. - If not, use
Global language
.
- If there is
- 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
git
for example, when enteringgit add
, pressing theSpace
andTab
keys, 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 pressTab
key to get path completion for the subdirectory or file. - Please enter
../
or..\
and pressTab
key to get path completion for the parent directory or file. - Please enter
/
or\
and pressTab
key to get path completion for the sibling directory. - More examples:
~/
/../../
...
- Please enter
- So you can enter
git add ./
and then pressTab
key to get the path completion.
Stars
If PSCompletions is helpful to you, please consider giving it a star.