Skip to content

Commit

Permalink
complete: work around slow "compgen -c" in Cygwin
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 11, 2020
1 parent 360211c commit 185a443
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/core-complete.sh
Expand Up @@ -618,11 +618,23 @@ function ble/complete/source:command/gen.1 {
(*:[mA]:*) local COMPS= COMPV= ;;
esac

# Note: cygwin では cyg,x86,i68 等で始まる場合にとても遅い。
# 他の環境でも空の補完を実行すると遅くなる可能性がある。
local slow_compgen=
if [[ ! $COMPV ]]; then
slow_compgen=1
elif [[ $OSTYPE == cygwin* ]]; then
case $COMPV in
(?|cy*|x8*|i6*)
slow_compgen=1 ;;
esac
fi

# Note: 何故か compgen -A command はクォート除去が実行されない。
# compgen -A function はクォート除去が実行される。
# 従って、compgen -A command には直接 COMPV を渡し、
# compgen -A function には compv_quoted を渡す。
if [[ ! $COMPV ]]; then
if [[ $slow_compgen ]]; then
shopt -q no_empty_cmd_completion && return
ble/util/conditional-sync \
'compgen -c -- "$COMPV"' \
Expand Down

0 comments on commit 185a443

Please sign in to comment.