@@ -40,10 +40,10 @@ or with Docker:
4040$ alias completely=' docker run --rm -it --user $(id -u):$(id -g) --volume "$PWD:/app" dannyben/completely'
4141```
4242
43- ## Using the ` completely ` command line
43+ ## Configuration syntax
4444
45- The ` completely ` command line works with a simple YAML configuration file as
46- input, and generates a bash completions script as output.
45+ Completely works with a simple YAML configuration file as input, and generates
46+ a bash completions script as output.
4747
4848The configuration file is built of blocks that look like this:
4949
@@ -59,45 +59,42 @@ for the auto complete process.
5959
6060You can save a sample YAML file by running:
6161
62- ` ` `
62+ ` ` ` bash
6363$ completely init
6464```
6565
6666This will generate a file named ` completely.yaml ` with this content:
6767
6868``` yaml
6969mygit :
70+ - -h
71+ - -v
7072- --help
7173- --version
72- - status
7374- init
74- - commit
75+ - status
76+
77+ mygit init :
78+ - --bare
79+ - <directory>
7580
7681mygit status :
7782- --help
7883- --verbose
7984- --branch
80- - $(git branch --format='%(refname:short)' 2>/dev/null)
85+ - -b
8186
82- mygit init :
83- - --bare
84- - <directory>
87+ mygit status*--branch : &branches
88+ - $(git branch --format='%(refname:short)' 2>/dev/null)
8589
86- mygit commit :
87- - <file>
88- - --help
89- - --message
90- - --all
91- - -a
92- - --quiet
93- - -q
90+ mygit status*-b : *branches
9491` ` `
9592
9693Each pattern in this configuration file will be checked against the user's
97- input, and if the input **starts with** a matching pattern, the list that
98- follows it will be suggested as completions.
94+ input, and if the input matches the pattern, the list that follows it will be
95+ suggested as completions.
9996
100- Note that the suggested completions will not show flags (string that start with
97+ Note that the suggested completions will not show flags (strings that start with
10198a hyphen ` -`) unless the input ends with a hyphen.
10299
103100To generate the bash script, simply run :
@@ -207,6 +204,48 @@ mygit checkout*--branch: &branches
207204mygit checkout*-b: *branches
208205` ` `
209206
207+ # ## Alternative nested syntax
208+
209+ Completely also supports an alternative nested syntax. You can generate this
210+ example by running :
211+
212+ ` ` ` bash
213+ $ completely init --nested
214+ ` ` `
215+
216+ The example configuration below will generate the exact same script as the one
217+ shown at the beginning of this document.
218+
219+ ` ` ` yaml
220+ mygit:
221+ - -h
222+ - -v
223+ - --help
224+ - --version
225+ - init:
226+ - --bare
227+ - <directory>
228+ - status:
229+ - --help
230+ - --verbose
231+ - +--branch: &branches
232+ - $(git branch --format='%(refname:short)' 2>/dev/null)
233+ - +-b: *branches
234+ ` ` `
235+
236+ The rules here are as follows :
237+
238+ - Each pattern (e.g., `mygit`) can have a mixed array of strings and hashes.
239+ - Strings and hash keys (e.e., `--help` and `init` respectively) will be used
240+ as completion strings for that pattern.
241+ - Hashes may contain a nested mixed array of the same structure.
242+ - When a hash is provided, the hash key will be appended to the parent prefix.
243+ In the example above, the `init` hash will create the pattern `mygit init`.
244+ - In order to provide a wildcard (like `mygit status*--branch` in the standard
245+ configuration syntax), you can provide either a `*` or a `+` prefix to the
246+ hash key (e.g., `+--branch` or `"*--branch"`). Note that when using a `*`,
247+ the hash key must be quoted since asterisks have special meaning in YAML.
248+
210249# # Using the generated completion scripts
211250
212251In order to enable the completions, simply source the generated script :
0 commit comments