Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(command): support zsh fpath completion #703

Merged
merged 1 commit into from
May 16, 2024

Conversation

andrewthauer
Copy link
Contributor

@andrewthauer andrewthauer commented May 15, 2024

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.

  • ensure #compdef <cmd> is on the first line
  • DO NOT add the (( $+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.
  • The end block checks funcstack and runs the _<cmd> $@ or falls back to the compgen command. This was copied from the deno completions. I believe this is to allow the completions to work when sourcing manually or used on the fpath. 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 and compinit called in your zsh setup
4. 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 example oh-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.

@andrewthauer andrewthauer changed the title fix(command): support zsh fpath completion feat(command): support zsh fpath completion May 15, 2024
Copy link
Owner

@c4spar c4spar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thx for this improvement @andrewthauer 👍 LGTM!

@c4spar
Copy link
Owner

c4spar commented May 16, 2024

It seems like github thinks there is a conflict, although that is not the case. can you squash all the commits into one please? then I can merge it locally.

fmt

add braces

disable shellcheck rule

update snapshots
@andrewthauer
Copy link
Contributor Author

Done!

@c4spar
Copy link
Owner

c4spar commented May 16, 2024

Awesome, thx! 👍

@c4spar c4spar merged commit f770de2 into c4spar:main May 16, 2024
26 checks passed
@andrewthauer andrewthauer deleted the zsh-fpath-completion branch May 16, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support automatic zsh completions with fpath
2 participants