Skip to content

Commit 0dd8fe4

Browse files
authored
fix(zsh): completion no longer requires double tab when using autoloaded
1 parent 27eec18 commit 0dd8fe4

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Rules & Behavior
3838
return a Promise [boolean]
3939
```
4040

41-
* bash-completion shortcuts for commands and options.
41+
* generate completion scripts for Bash and Zsh for your command
4242
* and [tons more](/docs/api.md).
4343

4444
## Installation

docs/api.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,25 @@ discussion of the advanced features exposed in the Command API.
354354
Enable bash/zsh-completion shortcuts for commands and options.
355355

356356
`cmd`: When present in `argv._`, will result in the `.bashrc` or `.zshrc` completion script
357-
being outputted. To enable bash/zsh completions, concat the generated script to your
358-
`.bashrc` or `.bash_profile` (or `.zshrc` for zsh).
357+
being outputted.
358+
359+
To enable bash/zsh completions, you can either:
360+
1. Concat the generated script to your
361+
`.bashrc` or `.bash_profile` (or `.zshrc` for zsh).
362+
363+
e.g. `./command completion > ~/.bashrc`
364+
365+
2. If you have `bash-completion` installed, write it to a file in
366+
`$XDG_DATA_HOME/bash-completion` (or `~/.local/share/bash-completion`),
367+
with the same name as the command.
368+
369+
e.g. `./command completion > ${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/command`
370+
371+
3. For Zsh, write it to a file in your `$fpath` named
372+
`_{{app_name}}_yargs_completions` where `{{app_name}}` is your
373+
command name.
374+
375+
e.g. `./command completion > /usr/local/share/zsh/site-functions/_command_yargs_completions`
359376

360377
`description`: Provide a description in your usage instructions for the command
361378
that generates the completion scripts.

lib/completion-templates.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ _{{app_name}}_yargs_completions()
4949
_default
5050
fi
5151
}
52-
compdef _{{app_name}}_yargs_completions {{app_name}}
52+
if [[ "'\${zsh_eval_context[-1]}" == "loadautofunc" ]]; then
53+
_{{app_name}}_yargs_completions "$@"
54+
else
55+
compdef _{{app_name}}_yargs_completions {{app_name}}
56+
fi
5357
###-end-{{app_name}}-completions-###
5458
`;

0 commit comments

Comments
 (0)