Skip to content

Commit

Permalink
complete: attempt no completion for arguments in check-here context
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 6, 2021
1 parent c1cd666 commit 371a5a4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -119,6 +119,7 @@
- util: time out <kbd>CPR</kbd> requests `#D1669` 1481d48
- main: suppress non-interactive warnings from manually sourced startup files (reported by andreclerigo) `#D1676` 0525528 88e2df5
- mandb: integrate `mandb` with `bash-completion` (motivated by Shahabaz-Bagwan, bbyfacekiller and EmilySeville7cfg) `#D1688` 0000000
- syntax: do not start argument completions immediately after previous word (reported by EmilySeville7cfg) `#D1690` 0000000

## Fixes

Expand Down
32 changes: 10 additions & 22 deletions lib/core-syntax.sh
Expand Up @@ -5678,6 +5678,16 @@ function ble/syntax/completion-context/.check-here {
# 既に check-prefix で引っかかっている筈だから。
local ctx=${stat[0]}

# #D1690: 引数類の補完はその場で開始はしない事にする。以下は削除した。
# CTX_ARGX0, CTX_CPATX0, CTX_ARGX, CTX_FARGX{1..3}, CTX_SARGX1,
# CTX_CARGX{1,2}, CTX_TARGX{1,2}, CTX_COARGX
#
# 引数の類は開始点の前に必ず空白類が存在する筈なので、ここで補完が開始され
# た場合前の単語とくっついて予期せぬ結果になる。もし本当に一つの単語の中で
# 新しく補完候補を生成する必要があるのであれば、それはその単語に対する補完
# の一環として行われるべきであって、"新しい単語" としての補完である必要はな
# い。
#
if ((ctx==CTX_CMDX||ctx==CTX_CMDXV||ctx==CTX_CMDX1||ctx==CTX_CMDXT)); then
if ! shopt -q no_empty_cmd_completion; then
ble/syntax/completion-context/.add command "$index"
Expand All @@ -5691,28 +5701,6 @@ function ble/syntax/completion-context/.check-here {
ble/syntax/completion-context/.add wordlist:-rs:';:{:do' "$index"
elif ((ctx==CTX_CMDXD)); then
ble/syntax/completion-context/.add wordlist:-rs:'{:do' "$index"
elif ((ctx==CTX_ARGX0||ctx==CTX_CPATX0)); then
ble/syntax/completion-context/.add sabbrev "$index"
elif ((ctx==CTX_ARGX||ctx==CTX_CARGX1||ctx==CTX_FARGX3)); then
ble/syntax/completion-context/.add argument "$index"
elif ((ctx==CTX_FARGX1||ctx==CTX_SARGX1)); then
ble/syntax/completion-context/.add variable:w "$index"
ble/syntax/completion-context/.add sabbrev "$index"
elif ((ctx==CTX_CARGX2)); then
ble/syntax/completion-context/.add wordlist:-rs:'in' "$index"
elif ((ctx==CTX_FARGX2)); then
ble/syntax/completion-context/.add wordlist:-rs:'in:do' "$index"
elif ((ctx==CTX_TARGX1)); then
local words='-p'
((_ble_bash>=50100)) && words='-p':'--'
ble/syntax/completion-context/.add command "$index"
ble/syntax/completion-context/.add wordlist:--:"$words" "$index"
elif ((ctx==CTX_TARGX2)); then
ble/syntax/completion-context/.add command "$index"
ble/syntax/completion-context/.add wordlist:--:'--' "$index"
elif ((ctx==CTX_COARGX)); then
ble/syntax/completion-context/.add variable:w "$index"
ble/syntax/completion-context/.add command "$index"
elif ((ctx==CTX_CPATI||ctx==CTX_RDRF||ctx==CTX_RDRS)); then
ble/syntax/completion-context/.add file "$index"
elif ((ctx==CTX_RDRD)); then
Expand Down
16 changes: 16 additions & 0 deletions note.txt
Expand Up @@ -5527,6 +5527,22 @@ bash_tips

2021-12-06

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

check-here を完全に消すと恐らくコマンド名を生成できない。

実装を確認した。ARGX 系統は直前に必ず空白の類が存在して check-prefix で生成
される。なので、ARGX 系統に関しては check-here から削除してしまって問題がな
い様に思われる。

元々、check-here に残していたのは、候補が全く生成できない時にその場で前の単
語に続けて生成したい事があるかもしれないという事だったが、よく考えてみれば
その様な使い方が有用な場合は意図的にその様に設計された限られた状況だし、そ
の様な状況の場合には、前の単語の補完の一部としてその様な候補を生成するべき
である。従って、check-here による ARGX 系統の補完文脈は寧ろ削除するべきであ
る。

* mandb: 空文字列の時にも mandb に基づくオプション生成を実行するべき [#D1689]

* 2021-08-30 complete: オプションの説明と progcomp の integration を考える (motivated by Shahabaz-Bagwan, bbyfacekiller and EmilySeville7cfg) [#D1688]
Expand Down

0 comments on commit 371a5a4

Please sign in to comment.