From 29e29d89aa7ea5c8f7fe64d482c3df3a9fbeacf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nivaldo=20Bondan=C3=A7a?= Date: Fri, 22 Mar 2024 13:38:04 -0400 Subject: [PATCH] [completion] Fixed autocomplete issue when using aliases (#500) Right now if we try to use tab-complete with an alias, we get the following error (reproduced on a macOS and zsh): unrecognized modifier `i' --------- Co-authored-by: AJ Alt --- CHANGELOG.md | 1 + .../github/ajalt/clikt/completion/BashCompletionGenerator.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a1549e4..c0a0ab62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - 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 +- Fixed `unrecognized modifier 'i'` that happened on tab-completion when using sub command aliases ([#500](https://github.com/ajalt/clikt/pull/500)) - 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 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 ea3b8825..3034516c 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 @@ -137,7 +137,7 @@ internal object BashCompletionGenerator { """ | $name) | (( i = i + 1 )) - | COMP_WORDS=( "${'$'}{COMP_WORDS[@]:0:i}" + | COMP_WORDS=( "${'$'}{COMP_WORDS[@]:0:${'$'}{i}}" """.trimMargin() ) toks.joinTo(this, " ", prefix = " ") { "'$it'" }