Skip to content

Commit 3fed3ef

Browse files
authored
Support different bash completion options (#1509)
#1508 Based on the documentation found here https://www.gnu.org/software/bash/manual/html_node/Commands-For-Completion.html we remove descriptions for the following completion types: - menu-complete - menu-complete-backward - insert-completions Signed-off-by: Marc Khouzam <[email protected]>
1 parent 507caf5 commit 3fed3ef

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

bash_completionsV2.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,42 @@ __%[1]s_process_completion_results() {
138138
_filedir -d
139139
fi
140140
else
141-
__%[1]s_handle_standard_completion_case
141+
__%[1]s_handle_completion_types
142142
fi
143143
144144
__%[1]s_handle_special_char "$cur" :
145145
__%[1]s_handle_special_char "$cur" =
146146
}
147147
148+
__%[1]s_handle_completion_types() {
149+
__%[1]s_debug "__%[1]s_handle_completion_types: COMP_TYPE is $COMP_TYPE"
150+
151+
case $COMP_TYPE in
152+
37|42)
153+
# Type: menu-complete/menu-complete-backward and insert-completions
154+
# If the user requested inserting one completion at a time, or all
155+
# completions at once on the command-line we must remove the descriptions.
156+
# https://github.com/spf13/cobra/issues/1508
157+
local tab comp
158+
tab=$(printf '\t')
159+
while IFS='' read -r comp; do
160+
# Strip any description
161+
comp=${comp%%%%$tab*}
162+
# Only consider the completions that match
163+
comp=$(compgen -W "$comp" -- "$cur")
164+
if [ -n "$comp" ]; then
165+
COMPREPLY+=("$comp")
166+
fi
167+
done < <(printf "%%s\n" "${out[@]}")
168+
;;
169+
170+
*)
171+
# Type: complete (normal completion)
172+
__%[1]s_handle_standard_completion_case
173+
;;
174+
esac
175+
}
176+
148177
__%[1]s_handle_standard_completion_case() {
149178
local tab comp
150179
tab=$(printf '\t')

0 commit comments

Comments
 (0)