feat(command): support zsh fpath completion #703
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #702.
These changes are based on patterns seen in other tools that generate zsh completions. If you run
deno completions zsh
you should be able to compare.#compdef <cmd>
is on the first line(( $+functions[<cmd>] ))
check on the root command. Doing so will create errors about function nesting. If you look, the_deno
completions it omits this on the root_deno
function.funcstack
and runs the_<cmd> $@
or falls back to thecompgen command
. This was copied from the deno completions. I believe this is to allow the completions to work when sourcing manually or used on thefpath
. I've confirmed this works locally for both explicit sourcing and fpath usage.Steps to test:
1 .Run
deno compile -A --output examples/cliffy examples/commands/demo.ts
2. Run
examples/cliffy completions zsh > /path/to/zsh/site-functions/_cliffy
3. Make sure you have
fpath=(/path/to/zsh/site-functions $fpath)
set andcompinit
called in your zsh setup4. Reload shell
5.
examples/cliffy
+<tab>
will now auto complete. No sourcing necessary._NOTE: Depending on the zsh setup there might be an already defined
fpath
which can be used. For exampleoh-my-zsh
uses~/.zfunc
by default. Linux systems, etc. might be in/usr/local/share/zsh/site-functions
, etc.Tests would be nice for this, but I didn't see any existing unit tests. I'm also not entirely sure howI would write an integration test with zsh proper either to cover this.