From ff6031a8ea549ca8deff1f163a43388cce936160 Mon Sep 17 00:00:00 2001 From: Huw Percival Date: Wed, 23 Feb 2022 10:40:29 +0000 Subject: [PATCH] re-write to use python, hopefully this is portable enough, tested with python 3.6.5 anf 2.7.18 --- src/_cmake | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/_cmake b/src/_cmake index cc5de89..20b88ac 100644 --- a/src/_cmake +++ b/src/_cmake @@ -141,13 +141,21 @@ _cmake_generator_options() { # -------------- (( $+functions[_cmake_presets] )) || _cmake_presets() { - local invoke; invoke=(${words[@]}) - # TODO: remove all arguments -* except -S - invoke[$CURRENT]=--list-presets + + local parse_presets; parse_presets=' +import json +import os +try: + with open("CMakePresets.json") as preset_file: + print(os.linesep.join([ x["name"] + ":" + x.get("description", "") for x in json.load(preset_file)["configurePresets"]])) +except: + pass + +' # TODO: Problems with quotes need eval # would need a way to exec the array - local list_presets; list_presets=(${(f)"$(eval "${invoke[@]} 2> /dev/null" | grep -Po '(?<=\").*(?=")' )"}) + local list_presets; list_presets=(${(f)"$(eval python <<< $parse_presets)"}) _describe 'presets' list_presets }