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 Jul 28, 2022
1 parent c01487b commit 7211b1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ble-core.sh
Expand Up @@ -613,8 +613,7 @@ else
fi

function ble/util/type {
_cmd=$2 ble/util/assign "$1" 'builtin type -t -- "$_cmd" 2>/dev/null'
builtin eval "$1=\"\${$1%$_ble_term_nl}\""
ble/util/assign-array "$1" 'builtin type -a -t -- "$3" 2>/dev/null' "$2"
}

if ((_ble_bash>=30200)); then
Expand Down
14 changes: 13 additions & 1 deletion lib/core-complete.sh
Expand Up @@ -234,14 +234,26 @@ function ble-complete/source/command {
local compgen
ble/util/assign compgen ble-complete/source/command/gen
[[ $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_stdin_frequency==0)) && ble/util/is-stdin-ready && return 148

# workaround: 何故か compgen -c -- "$COMPV" で
# 厳密一致のディレクトリ名が混入するので削除する。
[[ $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/yield-candidate "$cand" ble-complete/action/command
done
}
Expand Down

0 comments on commit 7211b1e

Please sign in to comment.