From f7a6e036ade1bce40e10a2575f4c677af5832a79 Mon Sep 17 00:00:00 2001 From: Robin Linden Date: Fri, 29 Apr 2022 14:33:19 +1000 Subject: bash-completion: Support CMakePresets in cmake and ctest completion Co-Authored-By: Craig Scott --- Auxiliary/bash-completion/cmake | 38 +++++++++++++++++++++++++++++++++++++- Auxiliary/bash-completion/ctest | 11 +++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Auxiliary/bash-completion/cmake b/Auxiliary/bash-completion/cmake index d8d2c86..bed7248 100644 --- a/Auxiliary/bash-completion/cmake +++ b/Auxiliary/bash-completion/cmake @@ -96,7 +96,15 @@ _cmake() _filedir return ;; - --build|--install|--open) + --build) + # Seed the reply with non-directory arguments that we know are + # allowed to follow --build. _filedir will then prepend any valid + # directory matches to these. + COMPREPLY=( $( compgen -W "--preset --list-presets" -- "$cur" ) ) + _filedir -d + return + ;; + --install|--open) _filedir -d return ;; @@ -149,6 +157,34 @@ _cmake() 2>/dev/null | grep -v "^cmake version " )' -- "$cur" ) ) return ;; + --list-presets) + local IFS=$'\n' + local quoted + printf -v quoted %q "$cur" + + if [[ ! "${IFS}${COMP_WORDS[*]}${IFS}" =~ "${IFS}--build${IFS}" ]]; then + COMPREPLY=( $( compgen -W "configure${IFS}build${IFS}test${IFS}all" -- "$quoted" ) ) + fi + return + ;; + --preset) + local IFS=$'\n' + local quoted + printf -v quoted %q "$cur" + + local build_or_configure="configure" + if [[ "${IFS}${COMP_WORDS[*]}${IFS}" =~ "${IFS}--build${IFS}" ]]; then + build_or_configure="build" + fi + + local presets=$( cmake --list-presets="$build_or_configure" 2>/dev/null | + grep -o "^ \".*\"" | sed \ + -e "s/^ //g" \ + -e "s/\"//g" \ + -e 's/ /\\\\ /g' ) + COMPREPLY=( $( compgen -W "$presets" -- "$quoted" ) ) + return + ;; esac $split && return diff --git a/Auxiliary/bash-completion/ctest b/Auxiliary/bash-completion/ctest index 49343bb..3c629d2 100644 --- a/Auxiliary/bash-completion/ctest +++ b/Auxiliary/bash-completion/ctest @@ -103,6 +103,17 @@ _ctest() 2>/dev/null | grep -v "^ctest version " )' -- "$cur" ) ) return ;; + --preset) + local IFS=$'\n' + local quoted + printf -v quoted %q "$cur" + COMPREPLY=( $( compgen -W '$( ctest --list-presets 2>/dev/null | + grep -o "^ \".*\"" | sed \ + -e "s/^ //g" \ + -e "s/\"//g" \ + -e "s/ /\\\\ /g" )' -- "$quoted" ) ) + return + ;; esac if [[ "$cur" == -* ]]; then -- cgit v0.12