From 9e88759b19cd358e9af6f0d778b9a23990cf7f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 4 May 2022 23:23:02 +0300 Subject: [PATCH] perf(bash-v2): speed up filtering menu-complete descriptions (#1692) 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 a06ab45..5e558a5 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}")