From 1a875e2b747c74b81a904ae6e6b82108a7346401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 4 May 2022 11:33:42 +0300 Subject: [PATCH] perf(bash-v2): speed up filtering menu-complete descriptions Similarly as fb8031162c2ffab270774f13c6904bb04cbba5a7 (+ the empty entry fix) did for the "regular", non-menu completion cases. --- bash_completionsV2.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash_completionsV2.go b/bash_completionsV2.go index a06ab456c..5e558a511 100644 --- a/bash_completionsV2.go +++ b/bash_completionsV2.go @@ -156,11 +156,11 @@ __%[1]s_handle_completion_types() { # https://github.com/spf13/cobra/issues/1508 local tab=$'\t' comp while IFS='' read -r comp; do + [[ -z $comp ]] && continue # Strip any description comp=${comp%%%%$tab*} # Only consider the completions that match - comp=$(compgen -W "$comp" -- "$cur") - if [ -n "$comp" ]; then + if [[ $comp == "$cur"* ]]; then COMPREPLY+=("$comp") fi done < <(printf "%%s\n" "${out}")