Bash autocompleter is a command line utility to generate autocomplete scripts for bash and zsh.
The syntax for schemas is loosely based on completely.
shell
npm install --save-dev bash-autocompleter
`
`shell
yarn add -D bash-autocompleter
`Using
bash-autocompleter command line
Bash autocompleter will generate shell script either to a file or stdout based on json or yaml schema.`shell
bash-autocompleter schema.yaml -o autocomplete.sh
`An example yaml schema:
`yaml
mygit:
- --help
- --version
- status
- init
- commitmygit status:
- --help
- --verbose
- --branch
- $(git branch 2> /dev/null)
mygit diff:
- --cached
- --no-index
-
- $(git branch 2> /dev/null)
Add files after double dash operator. It should be lowest priority of wildcard
--.
mygit diff--: mygit init:
- --bare
-
mygit commit:
-
- --help
- --message
- --all
- -a
- --quiet
- -q
`Order of precedence in the schema file is top to bottom. If there are conflicts, the topmost schema will be taken first.
$3
If you're running on OSX or a very old version of bash you can use:
`shell
bash-autocompleter schema.yaml --bash3 -o autocomplete.sh
`
This will generate bash3 compatible scripts.
Wildcards
It's possible to use wildcards to signify what longer commands would look like. For example, below you can see what the autocomplete command for bash-autocompleter schema.yml -o would look like in the section.`yaml
bash-autocompleter:
-
- -o
- --bash3bash-autocompleter*-o:
-
`Empty arguments
If you have an argument that has no suggestion, use . For example, in git, the force flag doesn't have any followup options so would use .`yaml
git*--force: git*-f:
-
`References
Sometimes it's a lot of effort to duplicate flags that have the same content. For these, you can use references.`yaml
build*--config: &build-test
- debug
- releasebuild-c: build-test
`The above code will make
build -c and build --config