completion: avoid long running commands in shell startup

This commit is contained in:
Steffen Vogel 2019-04-17 10:22:07 +02:00
parent d74d02cf34
commit 3ab1c940c2

View file

@ -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
fi