From bd9af4b15a859949b0c0e87439ab39b0808d36b6 Mon Sep 17 00:00:00 2001 From: Aiden Woodruff Date: Sat, 22 Aug 2026 12:18:41 -0400 Subject: [PATCH] bash-completion: Improve compatibility with old bash It is not uncommon for packages to install cmake's bash-completion without depending on common bash-completion helper scripts. This commit improves compatibility in those scenarios. --- Auxiliary/bash-completion/cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Auxiliary/bash-completion/cmake b/Auxiliary/bash-completion/cmake index 7f5c71fe07..bdcbce74dc 100644 --- a/Auxiliary/bash-completion/cmake +++ b/Auxiliary/bash-completion/cmake @@ -97,7 +97,7 @@ _cmake() ;; esac - if $is_old_completion; then + if $is_old_completion && type -t _split_longopt >/dev/null; then _split_longopt && split=true fi @@ -252,6 +252,12 @@ _cmake() [[ $was_split ]] && return fi + if ! type -t _parse_help >/dev/null; then + _parse_help() { + "$@" | sed -e 's/^[ ]*\(-[-A-Za-z]*\).*$/\1/;t' -e d + } + fi + if [[ "$cur" == -* ]]; then # FIXME(#26100): `cmake --help` is missing some options and does not # have any mode-specific options like `cmake --build`'s `--config`. @@ -260,7 +266,11 @@ _cmake() [[ $COMPREPLY ]] && return fi - _filedir + if type -t _filedir >/dev/null; then + _filedir + else + COMPREPLY=( $(compgen -fd -- ${cur}) ) + fi } && complete -F _cmake cmake