Skip to content

Commit

Permalink
complete: support "complete [-DI]" in old versions of Bash through "_…
Browse files Browse the repository at this point in the history
…DefaultCmD_" and "_InitialWorD_"
  • Loading branch information
akinomyoga committed Sep 4, 2021
1 parent d347fb3 commit 925b2cd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/core-complete.sh
Expand Up @@ -1651,8 +1651,8 @@ function ble/complete/source:command {
[[ $COMPV =~ ^.+/ ]] && COMP_PREFIX=${BASH_REMATCH[0]}
local arg=$1

# Try progcomp by "complete -I"
if ((_ble_bash>=50000)); then
# Try progcomp by "complete -p -I" / "complete -p _InitialWorD_"
{
local old_cand_count=$cand_count

local comp_opts=:
Expand All @@ -1661,7 +1661,7 @@ function ble/complete/source:command {
if ((ext==0)); then
((cand_count>old_cand_count)) && return "$ext"
fi
fi
}

ble/complete/source:sabbrev

Expand Down Expand Up @@ -2493,13 +2493,22 @@ function ble/complete/progcomp/.compgen {
local compcmd= is_default_completion= is_special_completion=
local -a alias_args=()
if [[ :$opts: == *:initial:* ]]; then
is_special_completion=1
compcmd='-I'
if ((_ble_bash>=50000)); then
is_special_completion=1
compcmd='-I'
else
compcmd=_InitialWorD_
fi
elif [[ :$opts: == *:default:* ]]; then
builtin complete -p -D &>/dev/null || return 1
is_special_completion=1
is_default_completion=1
compcmd='-D'
if ((_ble_bash>=40100)); then
builtin complete -p -D &>/dev/null || return 1
is_special_completion=1
compcmd='-D'
else
builtin complete -p _DefaultCmD_ &>/dev/null || return 1
compcmd=_DefaultCmD_
fi
else
compcmd=${comp_words[0]}
fi
Expand Down
1 change: 1 addition & 0 deletions memo/ChangeLog.md
Expand Up @@ -59,6 +59,7 @@
- rlfunc: support vi word operations in `emacs` keymap (requested by SolarAquarion) `#D1624` 21d636a
- edit: support `TMOUT` for the session timeout `#D1631` 0e16dbd
- edit: support bash-5.2 `READLINE_ARGUMENT` `#D1638` 0000000
- complete: support `complete [-DI]` in old versions of Bash through `_DefaultCmD_` and `_InitialWorD_` `#D1639` 0000000

## Changes

Expand Down
11 changes: 11 additions & 0 deletions note.txt
Expand Up @@ -4991,6 +4991,17 @@ bash_tips

2021-09-01

* complete: 古い bash における -D, -I の対応 [#D1639]

どうやら -D, -I はそれぞれ内部的には _DefaultCmD_, _InitialWorD_ という名
前のコマンドに対する補完として実装されている様である。だとすれば、古い bash
の version で -D, -I に対応するとしたらこれらの単語に対して検査すれば良いの
ではないか。

というか現在の実装で古い bash ではどの様に振る舞うのだったか。
確認した。 -I に関しては version を確認して処理している。
-D に関しては complete -p -D が成功するかどうかで動作を変更している。

* 2021-05-03 edit: support bash-5.2 READLINE_ARGUMENT [#D1638]

5.2 新機能: READLINE_ARGUMENT: 調べてみると引数が存在している時にのみ定義さ
Expand Down

0 comments on commit 925b2cd

Please sign in to comment.