-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support Zsh completion autoload #31
Conversation
With this, you can just dump the script in your Zsh fpath and it will be loaded as needed by the completion system Fixes pnpm/pnpm#8232
@segevfiner I replaced "Fixes" in your comment with "Related" because merging this PR alone is not sufficient. pnpm must be update with the latest version of tabtab in a separate commit. |
#compdef {pkgname} | ||
###-begin-{pkgname}-completion-### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ###-begin-{pkgname}-completion-###
and ###-end-{pkgname}-completion-###
are there to determine the range of generate code should it be inserted to .zshrc
. I have some questions:
- Must
compdef
strictly be at the top? - Would it affect the
pnpm completion zsh >> ~/.zshrc
use-case? - Would it affect the
pnpm completion zsh > pnpm-completion.zsh
+source pnpm-completion.zsh
use-case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compdef
must be the first line in the file, for it to be recognized by the completion autoload system, see https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Autoloaded-files for reference.- Depends on what the condition on
zsh_eval_context
evaluates to when zsh sources.zshrc
, if it doesn't work, we can try a different condition, such as[[ $funcstack[1] = _{pkgname}_completion ]]
that some other such completion files use. - That should still work.
@@ -13,6 +14,14 @@ if type compdef &>/dev/null; then | |||
_describe 'values' reply | |||
fi | |||
} | |||
compdef _{pkgname}_completion {pkgname} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I did a bit of research and found that #compdef {pkgname}
replaces this. The use-cases I listed above would be affected.
Although, it seems that #compdef {pkgname}
is strictly necessary for lazily loading completion file.
Therefore, I request that:
- If lazy loading is strictly incompatible with the use-cases I listed above, please create new entry for
zsh-lazy
with new template file. The relevant files areconstants.js
andinstaller.js
. - If there is a way to be compatible with all use-cases in a single file, please make the necessary modifications for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what the if
is for, for supporting both in the same file. When the file is source
ed it will call compdef
(With the #compdef
line being just a comment), while when called by the completion system it will run the completion function.
I haven't tested appending to .zshrc
though, which might require adjusting the condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested appending to
.zshrc
though, which might require adjusting the condition.
Please do. And tell me the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work fine in .zshrc
as well. In .zshrc
$zsh_eval_context
is file
, which will make the snippet call compdef
as needed.
With this, you can just dump the script in your Zsh fpath and it will be loaded as needed by the completion system
Related pnpm/pnpm#8232
cc @KSXGitHub