Skip to content

Commit 67bd238

Browse files
docs: describe shell completion
Covers what completes, that `@bomb.sh/tab` has to be installed for it, and the line to add per shell. Also lists `complete` among the commands in both readmes, the second of which quotes `--help` and so has to match it. Co-authored-by: AmirSa12 <amirhosseinpr184@gmail.com>
1 parent da04338 commit 67bd238

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- [Packages](#packages)
2727
- [Commands](#commands)
2828
- [Getting started](#getting-started)
29+
- [Shell completion](#shell-completion)
2930
- [Exit codes and their meanings](#exit-codes-and-their-meanings)
3031
- [Contributing and Internal Documentation](#contributing-and-internal-documentation)
3132
- [Funding](#funding)
@@ -58,6 +59,7 @@ Supporting developers is an important task for webpack CLI.
5859
Thus, webpack CLI provides different commands for many common tasks.
5960

6061
- [`build|bundle|b [entries...] [options]`](https://webpack.js.org/api/cli/#build) - Run webpack (default command, can be omitted).
62+
- `complete [shell]` - Print a shell completion script, see [Shell completion](#shell-completion).
6163
- [`configtest|t [config-path]`](https://webpack.js.org/api/cli/#configtest) - Validate a webpack configuration.
6264
- [`help|h [command] [option]`](https://webpack.js.org/api/cli/#help) - Display help for commands and options.
6365
- [`info|i [options]`](https://webpack.js.org/api/cli/#info) - Returns information related to the local environment.
@@ -79,6 +81,41 @@ npx create-webpack-app init
7981

8082
You will then be prompted for some questions about which features you want to use, such as `scss`, `typescript`, `PWA` support or other features.
8183

84+
## Shell completion
85+
86+
Commands, their options and the values those options accept can be completed in `zsh`, `bash`, `fish` and `powershell`. The completions are read from webpack's own schema, so they cover whatever your webpack and `webpack-dev-server` versions support.
87+
88+
Completion is served by [`@bomb.sh/tab`](https://www.npmjs.com/package/@bomb.sh/tab), which is optional and not installed with `webpack-cli`:
89+
90+
```sh
91+
npm install --save-dev @bomb.sh/tab
92+
```
93+
94+
Then load the script for your shell:
95+
96+
```sh
97+
# zsh
98+
echo 'source <(webpack complete zsh)' >> ~/.zshrc
99+
100+
# bash
101+
echo 'source <(webpack complete bash)' >> ~/.bashrc
102+
103+
# fish
104+
webpack complete fish > ~/.config/fish/completions/webpack.fish
105+
106+
# powershell
107+
webpack complete powershell > ~/.webpack-completion.ps1
108+
echo '. ~/.webpack-completion.ps1' >> $PROFILE
109+
```
110+
111+
Once the shell is restarted, `Tab` completes commands, their aliases, options and option values:
112+
113+
```sh
114+
webpack b<Tab> # webpack build
115+
webpack build --mode=<Tab> # development, production, none
116+
webpack serve --his<Tab> # webpack serve --history-api-fallback
117+
```
118+
82119
## Exit codes and their meanings
83120

84121
| Exit Code | Description |

packages/webpack-cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ npx webpack-cli --help verbose
6464

6565
```
6666
build|bundle|b [entries...] [options] Run webpack (default command, can be omitted).
67+
complete [shell] Generate shell completion scripts.
6768
configtest|t [config-path] Validate a webpack configuration.
6869
help|h [command] [option] Display help for commands and options.
6970
info|i [options] Outputs information about your system.

0 commit comments

Comments
 (0)