From cf08b3db3b5785f4d1ae9cdae3f44c71f74e366a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Wo=C5=9B?= Date: Tue, 25 Feb 2020 22:09:01 +0100 Subject: [PATCH] Trim to subprojects name only until a single one is chosen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Woś fix completion when single subproject is left Fix completion when starting with ':' remove todo cosmetics trim to subprojects - ported to zsh --- _gradle | 51 ++++++++++++++++++++++++++++++++++++++++-- gradle-completion.bash | 50 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/_gradle b/_gradle index 10efa24..294879b 100644 --- a/_gradle +++ b/_gradle @@ -142,6 +142,51 @@ __gradle-completion-init() { return 0 } +# Instead of printing all tasks for all subprojects, print only subprojects names to limit number of entries shown on the screen +# Once a single subproject is choosen - return its all available tasks. +__gradle-trim-tasks-to-subprojects() { + if [[ "$1" =~ ^(.+:.*) ]]; then + # do nothing if a subproject is already choosen + cat + else + awk -F '[[:alnum:]_]:' '{ + # Split entries into (subprojects names) AND (tasks accessible from root project) + if ($1 ~ /:/) { + # keep only subproject name (skip task name part) + c = split($1, arr, "\\\\:") + + if (c == 3) { + current = "\\:" arr[c-1] "\\:" + } else { + current = arr[c-1] "\\:" + } + # keep uniq names (it assumes that the input to this funtion is already sorted) + if (m == 0 || current != module[m-1]) { + module[m++] = current + } + module_task_line[mtl++] = $0 + } else { + # otherwise store the whole line with description + root_task_line[rtl++] = $0 + } + } END { + for(i=0; i 1) { + for(i=0; i 1) { + for(i=0; i