Skip to content

Commit

Permalink
Add wildcard search to match any portion of command
Browse files Browse the repository at this point in the history
Update readme
  • Loading branch information
surajp committed Jan 25, 2021
1 parent b624467 commit c18ebf5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell: Attach to PowerShell Host Process",
"type": "PowerShell",
"request": "attach",
"runspaceId": 1
}
]
}
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# Autocomplete script for sfdx on windows powershell

### Also works on powershell core
### Also works in powershell core

![](media/autocomplete.gif)

### Requirements

- sfdx
- powershell (regular or powershell core)

### Copy this script file (sfdx-autocomplete.ps1) to any directory on your machine. Add a reference to the script in your profile.ps1. Refer to the link below for instructions on how to create your custom powershell profile
### Copy this script file (sfdx-autocomplete.ps1) to any directory on your machine. Add a reference to the script in your profile.ps1. Refer to the link below for instructions on how to create your custom powershell profile

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7

### Working
### Type in 'sfdx' followed by any portion of the command you're looking for in part or full. It will cycle through all commands that contain the string, in alphabetical order
### How to use

- Type in 'sfdx' followed by any portion of the command you're looking for. For eg: Type in `sfdx` followed by a space and `lightning` to see all `force:lightning` commands, or `test` to see all commands associated with running tests.
- After you type in a command, add double hyphens (`--`) followed by `<TAB><TAB>` to see the list of flags associated with the command, that you can then tab through.

### Note:

<sup><sub>The script creates a 'command.sfdx' file in your home directory each time a powershell session is started. This file contains all the sfdx commands. It is created in the background to avoid blocking the user. So, you might experience a slight delay in autocomplete to start working the very first time</sup></sub>
- For the autocomplete effect seen in the gif above, add the following line to your powershell profile
```js
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
```
- The script creates a '.sfdxcommands.json' file in your home directory each time a powershell session is started. This file contains all the sfdx commands. It is created in the background to avoid blocking the user. So, you might experience a slight delay in autocomplete to start working the very first time you install this script.
2 changes: 1 addition & 1 deletion sfdx-autocomplete.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $scriptBlock = {
}
elseif ($commandAst.CommandElements.Count -eq 2 -and $wordToComplete -ne "") {
<# Completing a command #>
$commandPattern = "^(force:)?" + $commandAst.CommandElements[1].Value + ".+" <# Complete if force: is not specified too #>
$commandPattern = ".*" + $commandAst.CommandElements[1].Value + ".*" <# Complete if force: is not specified too #>
$script:sfdxCommands | Where-Object id -match $commandPattern | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_.id, $_.id, 'Method', $_.description)
}
Expand Down

0 comments on commit c18ebf5

Please sign in to comment.