Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Features
- ``bash``
- ``zsh``
- ``tcsh``
- ``powershell``

- Supports

Expand Down Expand Up @@ -60,8 +61,8 @@ There are two ways of using ``shtab``:
- `Library Usage <https://docs.iterative.ai/shtab/use/#library-usage>`_: as a library integrated into your CLI application

- adds a couple of lines to your application
- argument mode: end-users execute ``your_cli_app --print-completion {bash,zsh,tcsh}``
- subparser mode: end-users execute ``your_cli_app completion {bash,zsh,tcsh}``
- argument mode: end-users execute ``your_cli_app --print-completion {bash,zsh,tcsh,powershell}``
- subparser mode: end-users execute ``your_cli_app completion {bash,zsh,tcsh,powershell}``

Examples
--------
Expand Down Expand Up @@ -98,7 +99,6 @@ Contributions
Please do open `issues <https://github.com/iterative/shtab/issues>`_ & `pull requests <https://github.com/iterative/shtab/pulls>`_! Some ideas:

- support ``fish`` (`#174 <https://github.com/iterative/shtab/pull/174>`_)
- support ``powershell``

See
`CONTRIBUTING.md <https://github.com/iterative/shtab/tree/main/CONTRIBUTING.md>`_
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- `bash`
- `zsh`
- `tcsh`
- `powershell`
- Supports
- [argparse](https://docs.python.org/library/argparse)
- [docopt](https://pypi.org/project/docopt) (via [argopt](https://pypi.org/project/argopt))
Expand Down Expand Up @@ -110,7 +111,6 @@ application. Use `-u, --error-unimportable` to noisily complain.
Please do open [issues][GH-issue] & [pull requests][GH-pr]! Some ideas:

- support `fish` ([#174](https://github.com/iterative/shtab/pull/174))
- support `powershell`

See
[CONTRIBUTING.md](https://github.com/iterative/shtab/tree/main/CONTRIBUTING.md)
Expand Down
38 changes: 36 additions & 2 deletions docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ There are two ways of using `shtab`:
- end-users execute `shtab your_cli_app.your_parser_object`
- [Library Usage](#library-usage): as a library integrated into your CLI application
- adds a couple of lines to your application
- argument mode: end-users execute `your_cli_app --print-completion {bash,zsh,tcsh}`
- subparser mode: end-users execute `your_cli_app completion {bash,zsh,tcsh}`
- argument mode: end-users execute `your_cli_app --print-completion {bash,zsh,tcsh,powershell}`
- subparser mode: end-users execute `your_cli_app completion {bash,zsh,tcsh,powershell}`

## CLI Usage

Expand Down Expand Up @@ -98,6 +98,32 @@ Below are various examples of enabling `shtab`'s own tab completion scripts.
| sudo tee /etc/profile.d/eager-completion.csh
```

=== "powershell"

```powershell
shtab --shell=powershell shtab.main.get_main_parser --error-unimportable `
| Out-File -FilePath ~\shtab_completion.ps1
. ~\shtab_completion.ps1
```

=== "Eager powershell"

Add the following to your PowerShell profile (`$PROFILE`):

```powershell
shtab --shell=powershell shtab.main.get_main_parser `
| Out-String | Invoke-Expression
```

Or save to a file and dot-source it from your profile:

```powershell
shtab --shell=powershell shtab.main.get_main_parser `
| Out-File -FilePath ~\shtab_completion.ps1
# Add to $PROFILE:
. ~\shtab_completion.ps1
```

!!! tip
See the [examples/](https://github.com/iterative/shtab/tree/main/examples)
folder for more.
Expand Down Expand Up @@ -145,6 +171,14 @@ Assuming this code example is installed in `MY_PROG.command.main`, simply run:
| sudo tee /etc/profile.d/MY_PROG.completion.csh
```

=== "powershell"

```powershell
shtab --shell=powershell -u MY_PROG.command.main.get_main_parser `
| Out-File -FilePath ~\MY_PROG_completion.ps1
. ~\MY_PROG_completion.ps1
```

## Library Usage

!!! tip
Expand Down
12 changes: 10 additions & 2 deletions examples/customcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

TXT_FILE = {
"bash": "_shtab_greeter_compgen_TXTFiles", "zsh": "_files -g '(*.txt|*.TXT)'",
"tcsh": "f:*.txt"}
"tcsh": "f:*.txt", "powershell": "_shtab_greeter_compgen_TXTFiles"}
PREAMBLE = {
"bash": """
# $1=COMP_WORDS[1]
Expand All @@ -19,7 +19,15 @@
compgen -f -X '!*?.txt' -- $1
compgen -f -X '!*?.TXT' -- $1
}
""", "zsh": "", "tcsh": ""}
""", "zsh": "", "tcsh": "", "powershell": """
function _shtab_greeter_compgen_TXTFiles {
param([string]$WordToComplete)
Get-ChildItem -Path "$WordToComplete*" -Include '*.txt','*.TXT' -File -ErrorAction SilentlyContinue |
ForEach-Object { $_.Name }
Get-ChildItem -Path "$WordToComplete*" -Directory -ErrorAction SilentlyContinue |
ForEach-Object { $_.Name + [System.IO.Path]::DirectorySeparatorChar }
}
"""}


def process(args):
Expand Down
Loading