Skip to content

Commit

Permalink
complete: do not generate keywords for quoted command names
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jun 27, 2022
1 parent 99f2234 commit 5b1e5be
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions lib/core-complete.sh
Expand Up @@ -383,13 +383,18 @@ function ble/complete/action:command/init-menu-item {
if [[ -d $CAND ]]; then
ble/color/face2g filename_directory
else
# Note: ble/syntax/highlight/cmdtype はキャッシュ機能がついているが、
# キーワードに対して呼び出さない前提なのでキーワードを渡すと
# _ble_attr_ERR を返してしまう。
local type; ble/util/type type "$CAND"
ble/syntax/highlight/cmdtype1 "$type" "$CAND"
if [[ $CAND == */ ]] && ((type==_ble_attr_ERR)); then
type=_ble_attr_CMD_FUNCTION
local type
if [[ $CAND != "$INSERT" ]]; then
ble/syntax/highlight/cmdtype "$CAND" "$INSERT"
else
# Note: ble/syntax/highlight/cmdtype はキャッシュ機能がついているが、
# キーワードに対して呼び出さない前提なのでキーワードを渡すと
# _ble_attr_ERR を返してしまう。
local type; ble/util/type type "$CAND"
ble/syntax/highlight/cmdtype1 "$type" "$CAND"
if [[ $CAND == */ ]] && ((type==_ble_attr_ERR)); then
type=_ble_attr_CMD_FUNCTION
fi
fi
ble/syntax/attr2g "$type"
fi
Expand Down Expand Up @@ -743,14 +748,26 @@ function ble/complete/source:command {
local compgen
ble/util/assign compgen 'ble/complete/source:command/gen "$arg"'
[[ $compgen ]] || return 1
ble/util/assign-array arr 'sort -u <<< "$compgen"' # 1 fork/exec
ble/util/assign-array arr 'ble/bin/sort -u <<< "$compgen"' # 1 fork/exec

# keyword 判定用
local rex_keyword=
[[ $COMPS != $COMPV ]] &&
local rex_keyword='^(if|then|else|elif|fi|case|esac|for|select|while|until|do|done|function|time|[{}]|\[\[|coproc)$'

for cand in "${arr[@]}"; do
((i++%bleopt_complete_polling_cycle==0)) && ble/complete/check-cancel && return 148

# workaround: 何故か compgen -c -- "$compv_quoted" で
# 厳密一致のディレクトリ名が混入するので削除する。
[[ $cand != */ && -d $cand ]] && ! type "$cand" &>/dev/null && continue

# #D1691 keyword は quote されている場合には無効
if [[ $rex_keyword && $cand =~ $rex_keyword ]]; then
local type; ble/util/type type "$cand"
((${#type[@]}==1)) && continue
fi

ble/complete/cand/yield command "$cand"
done
}
Expand Down

0 comments on commit 5b1e5be

Please sign in to comment.