From 9a87ccf7963b7073ec86f5ae7647587755ca5953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nivaldo=20Bondan=C3=A7a?= Date: Fri, 22 Mar 2024 13:27:25 -0400 Subject: [PATCH] [complete][zsh] Fixing issue with compgen function not being found (#499) Depending on your version of zsh, you may not have `autoload compinit` called in your `.zshrc` file, which results in the following error (tested on a macOS): complete:13: command not found: compdef I found the solution here, which worked when tested: https://stackoverflow.com/a/76476988/1848826 --- CHANGELOG.md | 3 +++ .../github/ajalt/clikt/completion/BashCompletionGenerator.kt | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6914d43f2..4a1549e40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ - Added `limit` parameter to `option().counted()` to limit the number of times the option can be used. You can either clamp the value to the limit, or throw an error if the limit is exceeded. ([#483](https://github.com/ajalt/clikt/issues/483)) - Added `Context.registerClosable` and `Context.callOnClose` to allow you to register cleanup actions that will be called when the command exits. ([#395](https://github.com/ajalt/clikt/issues/395)) +### Fixed +- Make sure auto complete script works on zsh, fixing the error `complete:13: command not found: compdef` ([#499](https://github.com/ajalt/clikt/pull/499)) + ## 4.2.2 ### Changed - Options and arguments can now reference option groups in their `defaultLazy` and other finalization blocks. They can also freely reference each other, including though chains of references. ([#473](https://github.com/ajalt/clikt/issues/473)) diff --git a/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/completion/BashCompletionGenerator.kt b/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/completion/BashCompletionGenerator.kt index a8fb7c4bf..ea3b88259 100644 --- a/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/completion/BashCompletionGenerator.kt +++ b/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/completion/BashCompletionGenerator.kt @@ -38,7 +38,9 @@ internal object BashCompletionGenerator { if (zsh) { append( """ - |autoload bashcompinit + |autoload -Uz compinit + |compinit + |autoload -Uz bashcompinit |bashcompinit | |