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 Dec 6, 2021
1 parent 371a5a4 commit 60d244f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -189,6 +189,7 @@
- decode: fix a bug that the characters input while initialization are delayed `#D1670` 430f449
- util (`ble/util/readfile`): fix a bug of always exiting with 1 in `bash <= 3.2` (reported by laoshaw) `#D1678` 61705bf
- trace: fix wrong positioning of the ellipses on overflow `#D1684` 0000000
- complete: do not generate keywords for quoted command names `#D1691` 0000000

## Documentation

Expand Down
30 changes: 23 additions & 7 deletions lib/core-complete.sh
Expand Up @@ -1399,13 +1399,18 @@ function ble/complete/action:command/init-menu-item {
if [[ -d $CAND ]]; then
local ret; ble/color/face2g filename_directory; g=$ret
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 @@ -1913,13 +1918,24 @@ function ble/complete/source:command {

ble/complete/source/test-limit ${#arr[@]} || return 1

# 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
((cand_iloop++%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
20 changes: 10 additions & 10 deletions note.txt
Expand Up @@ -1915,16 +1915,6 @@ bash_tips
は auto-complete を抜けて再度 SP が実行されるのでちゃんと sabbrev も呼び出
される。

* complete: 'fo で補完すると 'for' になってしまうが for はキーワードなので駄目。

元々の compgen では対応しているのに ble.sh が勝手に quote を変更するから
駄目なのだろうかと思ったが、元の compgen -c ではそもそも "'f" や "'f'" を
渡しても何も候補生成されなかった。

更に plain Bash の補完でも 'fo で補完すると 'for' が補完されてしまう。と
いう事を考えると ble.sh だけの問題ではないのでそんなに気にしなくても良い
のかもしれない。

2021-09-06

* menu: メニューの詳細表示を toggle できる様にするべきではないか。
Expand Down Expand Up @@ -5527,6 +5517,16 @@ bash_tips

2021-12-06

* 2021-09-08 complete: 'fo で補完すると 'for' になってしまうが for はキーワードなので駄目 [#D1691]

元々の compgen では対応しているのに ble.sh が勝手に quote を変更するから
駄目なのだろうかと思ったが、元の compgen -c ではそもそも "'f" や "'f'" を
渡しても何も候補生成されなかった。

更に plain Bash の補完でも 'fo で補完すると 'for' が補完されてしまう。と
いう事を考えると ble.sh だけの問題ではないのでそんなに気にしなくても良い
のかもしれない。

* ble.sh: complete check-here を制限 (reported by EmilySeville7cfg) [#D1690]
https://github.com/akinomyoga/ble.sh/issues/156

Expand Down

0 comments on commit 60d244f

Please sign in to comment.