diff --git a/Cargo.lock b/Cargo.lock index 86b22c8bacd..47077ee6446 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -474,7 +474,7 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.26" +version = "4.5.27" dependencies = [ "automod", "clap 4.5.17", diff --git a/clap_complete/CHANGELOG.md b/clap_complete/CHANGELOG.md index 3406453c74d..779bce97c5d 100644 --- a/clap_complete/CHANGELOG.md +++ b/clap_complete/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +## [4.5.27] - 2024-09-17 + +### Fixes + +- *(dynamic)* Fix completions for bash for at least some users + ## [4.5.26] - 2024-09-05 ### Features @@ -414,7 +420,8 @@ MSRV changed to 1.64.0 ## [3.0.1] - 2022-01-03 -[Unreleased]: https://github.com/clap-rs/clap/compare/clap_complete-v4.5.26...HEAD +[Unreleased]: https://github.com/clap-rs/clap/compare/clap_complete-v4.5.27...HEAD +[4.5.27]: https://github.com/clap-rs/clap/compare/clap_complete-v4.5.26...clap_complete-v4.5.27 [4.5.26]: https://github.com/clap-rs/clap/compare/clap_complete-v4.5.25...clap_complete-v4.5.26 [4.5.25]: https://github.com/clap-rs/clap/compare/clap_complete-v4.5.24...clap_complete-v4.5.25 [4.5.24]: https://github.com/clap-rs/clap/compare/clap_complete-v4.5.23...clap_complete-v4.5.24 diff --git a/clap_complete/Cargo.toml b/clap_complete/Cargo.toml index 5f7d1b1d9b9..89f5eec6d7d 100644 --- a/clap_complete/Cargo.toml +++ b/clap_complete/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clap_complete" -version = "4.5.26" +version = "4.5.27" description = "Generate shell completion scripts for your clap::Command" categories = ["command-line-interface"] keywords = [ diff --git a/clap_complete/README.md b/clap_complete/README.md index 58fa8969f07..51cb41da5bf 100644 --- a/clap_complete/README.md +++ b/clap_complete/README.md @@ -5,16 +5,16 @@ [![Crates.io](https://img.shields.io/crates/v/clap_complete?style=flat-square)](https://crates.io/crates/clap_complete) [![Crates.io](https://img.shields.io/crates/d/clap_complete?style=flat-square)](https://crates.io/crates/clap_complete) -[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.5.26/LICENSE-APACHE) -[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.5.26/LICENSE-MIT) +[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.5.27/LICENSE-APACHE) +[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_complete-v4.5.27/LICENSE-MIT) Dual-licensed under [Apache 2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT). 1. [About](#about) 2. [API Reference](https://docs.rs/clap_complete) 3. [Questions & Discussions](https://github.com/clap-rs/clap/discussions) -4. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_complete-v4.5.26/clap_complete/CONTRIBUTING.md) -5. [Sponsors](https://github.com/clap-rs/clap/blob/clap_complete-v4.5.26/README.md#sponsors) +4. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_complete-v4.5.27/clap_complete/CONTRIBUTING.md) +5. [Sponsors](https://github.com/clap-rs/clap/blob/clap_complete-v4.5.27/README.md#sponsors) ## About diff --git a/clap_complete/src/env/mod.rs b/clap_complete/src/env/mod.rs index 69e0b1d7233..aa5a7964a77 100644 --- a/clap_complete/src/env/mod.rs +++ b/clap_complete/src/env/mod.rs @@ -295,6 +295,11 @@ pub trait EnvCompleter { /// Write the `buf` the logic needed for calling into `= --`, passing needed /// arguments to [`EnvCompleter::write_complete`] through the environment. /// + /// - `var`: see [`CompleteEnv::var`] + /// - `name`: an identifier to use in the script + /// - `bin`: the binary being completed + /// - `completer`: the command to run to generate completions + /// /// **WARNING:** There are no stability guarantees between the call to /// [`EnvCompleter::write_complete`] that this generates and actually calling [`EnvCompleter::write_complete`]. /// Caching the results of this call may result in invalid or no completions to be generated. diff --git a/clap_complete/src/env/shells.rs b/clap_complete/src/env/shells.rs index eb2cb10a080..521cb43e99f 100644 --- a/clap_complete/src/env/shells.rs +++ b/clap_complete/src/env/shells.rs @@ -23,8 +23,6 @@ impl EnvCompleter for Bash { buf: &mut dyn std::io::Write, ) -> Result<(), std::io::Error> { let escaped_name = name.replace('-', "_"); - let mut upper_name = escaped_name.clone(); - upper_name.make_ascii_uppercase(); let completer = shlex::try_quote(completer).unwrap_or(std::borrow::Cow::Borrowed(completer)); @@ -40,7 +38,7 @@ _clap_complete_NAME() { local _CLAP_COMPLETE_SPACE=true fi COMPREPLY=( $( \ - IFS="$IFS" \ + _CLAP_IFS="$IFS" \ _CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \ _CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" \ VAR="bash" \ @@ -61,7 +59,6 @@ fi .replace("NAME", &escaped_name) .replace("BIN", bin) .replace("COMPLETER", &completer) - .replace("UPPER", &upper_name) .replace("VAR", var); writeln!(buf, "{script}")?; @@ -85,7 +82,7 @@ fi let _space: Option = std::env::var("_CLAP_COMPLETE_SPACE") .ok() .and_then(|i| i.parse().ok()); - let ifs: Option = std::env::var("IFS").ok().and_then(|i| i.parse().ok()); + let ifs: Option = std::env::var("_CLAP_IFS").ok().and_then(|i| i.parse().ok()); let completions = crate::engine::complete(cmd, args, index, current_dir)?; for (i, candidate) in completions.iter().enumerate() { @@ -341,17 +338,18 @@ impl EnvCompleter for Zsh { fn write_registration( &self, var: &str, - _name: &str, + name: &str, bin: &str, completer: &str, buf: &mut dyn std::io::Write, ) -> Result<(), std::io::Error> { + let escaped_name = name.replace('-', "_"); let bin = shlex::try_quote(bin).unwrap_or(std::borrow::Cow::Borrowed(bin)); let completer = shlex::try_quote(completer).unwrap_or(std::borrow::Cow::Borrowed(completer)); let script = r#"#compdef BIN -function _clap_dynamic_completer() { +function _clap_dynamic_completer_NAME() { local _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1) local _CLAP_IFS=$'\n' @@ -367,7 +365,8 @@ function _clap_dynamic_completer() { fi } -compdef _clap_dynamic_completer BIN"# +compdef _clap_dynamic_completer_NAME BIN"# + .replace("NAME", &escaped_name) .replace("COMPLETER", &completer) .replace("BIN", &bin) .replace("VAR", var); diff --git a/clap_complete/tests/snapshots/home/dynamic-env/exhaustive/bash/.bashrc b/clap_complete/tests/snapshots/home/dynamic-env/exhaustive/bash/.bashrc index ffc7e7907bb..c07acde95fc 100644 --- a/clap_complete/tests/snapshots/home/dynamic-env/exhaustive/bash/.bashrc +++ b/clap_complete/tests/snapshots/home/dynamic-env/exhaustive/bash/.bashrc @@ -11,7 +11,7 @@ _clap_complete_exhaustive() { local _CLAP_COMPLETE_SPACE=true fi COMPREPLY=( $( \ - IFS="$IFS" \ + _CLAP_IFS="$IFS" \ _CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \ _CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" \ COMPLETE="bash" \ diff --git a/clap_complete/tests/snapshots/home/dynamic-env/exhaustive/zsh/zsh/_exhaustive b/clap_complete/tests/snapshots/home/dynamic-env/exhaustive/zsh/zsh/_exhaustive index b280f7c62e0..e59950fc841 100644 --- a/clap_complete/tests/snapshots/home/dynamic-env/exhaustive/zsh/zsh/_exhaustive +++ b/clap_complete/tests/snapshots/home/dynamic-env/exhaustive/zsh/zsh/_exhaustive @@ -1,5 +1,5 @@ #compdef exhaustive -function _clap_dynamic_completer() { +function _clap_dynamic_completer_exhaustive() { local _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1) local _CLAP_IFS=$'\n' @@ -15,4 +15,4 @@ function _clap_dynamic_completer() { fi } -compdef _clap_dynamic_completer exhaustive +compdef _clap_dynamic_completer_exhaustive exhaustive