From 3ab1c940c2729dd2614c783e4f94481472326d0b Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 17 Apr 2019 10:22:07 +0200 Subject: [PATCH] completion: avoid long running commands in shell startup --- home/.bash_completion | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/home/.bash_completion b/home/.bash_completion index c849da2..c223ddf 100644 --- a/home/.bash_completion +++ b/home/.bash_completion @@ -15,7 +15,27 @@ if type aws_completer > /dev/null 2>&1; then fi if type ykman > /dev/null 2>&1; then - source <(_YKMAN_COMPLETE=source ykman) + _ykman_completion() { + local IFS=$' +' + COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ + COMP_CWORD=$COMP_CWORD \ + _YKMAN_COMPLETE=complete $1 ) ) + return 0 + } + + _ykman_completionetup() { + local COMPLETION_OPTIONS="" + local BASH_VERSION_ARR=(${BASH_VERSION//./ }) + # Only BASH version 4.4 and later have the nosort option. + if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then + COMPLETION_OPTIONS="-o nosort" + fi + + complete $COMPLETION_OPTIONS -F _ykman_completion ykman + } + + _ykman_completionetup; fi if type kubectl > /dev/null 2>&1; then @@ -28,4 +48,4 @@ fi if type doctl > /dev/null 2>&1; then source <(doctl completion bash) -fi \ No newline at end of file +fi