From 061f09cd53620f71e5471248e4fe5f8935879f45 Mon Sep 17 00:00:00 2001 From: Norbert Lange Date: Tue, 19 Jul 2022 11:39:59 +0200 Subject: [PATCH] _cmake: fix cmake presets for real support presets without descriptions, and modify the commandline to add --list-presets at the end. Improve how cmake presets are listed, should be more robust in regards to quoting. --- src/_cmake | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/_cmake b/src/_cmake index 6955bcf..d1ccdc7 100644 --- a/src/_cmake +++ b/src/_cmake @@ -141,14 +141,13 @@ _cmake_generator_options() { # -------------- (( $+functions[_cmake_presets] )) || _cmake_presets() { - # TODO: Problems with quotes need eval - # would need a way to exec the array - local -a list_presets; + local invoke; invoke=(${(Q)words}) + invoke[$CURRENT]=() + # TODO: remove all arguments -* except -S - if [[ -e CMakePresets.json ]]; then - # some old projects uses BOM in json file. strip UTF-8 BOM and then parse JSON - list_presets=("${(@f)$(sed '1s/^\xEF\xBB\xBF//' < CMakePresets.json | perl -0777 -MJSON::PP -nE 'do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$_->{name}:$_->{description}\n"} for @{decode_json($_)->{configurePresets}}' 2>/dev/null)}") - fi + local list_presets; list_presets=(${(f)"$(${invoke} --list-presets 2>/dev/null | + sed -n -e 's,^[[:space:]]*"\([^"]*\)"[[:space:]]*-[[:space:]]*\(.*\),\1:\2,p' \ + -e 's,^[[:space:]]*"\([^"]*\)"[[:space:]]*$,\1,p')"}) _describe 'presets' list_presets }