Skip to content

Commit

Permalink
progcomp: work around the cobra V2 description hack
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 4, 2022
1 parent a9551e5 commit 71d0736
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 14 deletions.
29 changes: 15 additions & 14 deletions docs/ChangeLog.md
Expand Up @@ -84,20 +84,20 @@
- term: let <kbd>DECSCUSR</kbd> pass through terminal multiplexers (motivated by cmplstofB) `#D1697` a3349e4
- util: refactor `_ble_term_TERM` `#D1746` 63fba6b
- complete: requote for more compact representations on full completions `#D1700` a1859b6
- complete (requote): requote from optarg/rhs starting point `#D1786` 0000000
- complete (requote): requote from optarg/rhs starting point `#D1786` 93c2786
- complete: improve support for `declare` and `[[ ... ]]` `#D1701` da38404
- syntax: fix completion and highlighting of `declare` with assignment arguments `#D1704` `#D1705` e12bae4
- cmdspec: refactor `{mandb => cmdspec}_opts` `#D1706` `#D1707` 0786e92
- complete (menu-style:align): refactor `complete_menu_align => menu_align_{min,max}` (motivated by banoris) `#D1717` 22a2449
- prompt: support `bleopt prompt_command_changes_layout` `#D1750` e199bee
- exec: measure execution times `#D1756` 2b28bec
- edit: work around a bash-4.4..5.1 bug of `exit` outputting time to stderr of exit context `#D1765` 3de751e e61dbaa
- edit (`exec_elapsed_mark`): show hours and days `#D1793` 0000000
- edit (`exec_elapsed_mark`): show hours and days `#D1793` 699dabb
- util: preserve original traps and restore them on unload `#D1775` `#D1776` `#D1777` 398e404
- progcomp: support `compopt -o ble/no-default` to suppress default completions `#D1789` 0000000
- sabbrev: support options `-r` and `--reset` to remove entries `#D1790` 0000000
- util (blehook): support `hook!=handler` and `hook+-=handler` `#D1791` 0000000
- prompt: escape control characters in `\w` and `\W` `#D1798` 0000000
- progcomp: support `compopt -o ble/no-default` to suppress default completions `#D1789` 7b70a0e
- sabbrev: support options `-r` and `--reset` to remove entries `#D1790` 29b8be3
- util (blehook): support `hook!=handler` and `hook+-=handler` `#D1791` 0b8c097
- prompt: escape control characters in `\w` and `\W` `#D1798` 8940434 a9551e5

## Changes

Expand Down Expand Up @@ -135,7 +135,7 @@
- Makefile: work around the case the repository is cloned without `--recursive` `#D1655` 22ace5f
- repo: add subdirectories `make` and `docs` `#D1657` 75bd04c
- util: time out <kbd>CPR</kbd> requests `#D1669` 1481d48
- util (CPR): fix the problem of always timing out (fixup 1481d48) `#D1792` 0000000
- util (CPR): fix the problem of always timing out (fixup 1481d48) `#D1792` 9b331c4
- 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` c1cd666
- syntax: do not start argument completions immediately after previous word (reported by EmilySeville7cfg) `#D1690` 371a5a4
Expand All @@ -154,8 +154,8 @@
- complete (`action:file`): always suffix `/` to complete symlinked directory names (reported by SuperSandro2000) `#D1759` 397ac1f
- edit (command-help): show source files for functions `#D1779` 7683ab9
- edit (`ble/builtin/exit`): defer exit in trap handlers (motivated by SuperSandro2000) `#D1782` f62fc04 6fdabf3
- complete (`source:command/get-desc`): show function location and body `#D1788` 0000000
- edit (`ble-detach`): prepend a space to `stty sane` for `HISTIGNORE=' *'` `#D1796` 0000000
- complete (`source:command/get-desc`): show function location and body `#D1788` 496e798
- edit (`ble-detach`): prepend a space to `stty sane` for `HISTIGNORE=' *'` `#D1796` 26b532e

## Fixes

Expand All @@ -178,7 +178,7 @@
- mandb: insert a comma in brace expansions instead of a space `#D1719` 0ac7f03
- mandb: support man-page format of `rsync` `#D1733` 7900144
- mandb: fix a bug that the description is inserted for `--no-OPTION` `#D1761` 88614b8
- mandb: fix a bug that the man page is not correctly searched (fixup 2365e09) `#D1794` 0000000
- mandb: fix a bug that the man page is not correctly searched (fixup 2365e09) `#D1794` 65ffe70
- edit: work around the wrong job information of Bash in trap handlers (reported by 3ximus) `#D1435` `#D1436` bc4735e
- edit (command-help): work around the Bash bug that tempenv vanishes with `builtin eval` `#D1438` 8379d4a
- global: suppress missing locale errors (reported by 3ximus) `#D1440` 4d3c595
Expand Down Expand Up @@ -252,9 +252,9 @@
- app: work around data corruption by WINCH on intermediate state `#D1762` 5065fda
- util (`ble/util/import`): work around filenames with bash special characters `#D1763` b27f758
- edit: fix the restore failure of `PS1` and `PROMPT_COMMAND` on `ble-detach` `#D1784` b9fdaab
- complete: do not attempt an independent rhs completion for arguments (reported by rsteube) `#D1787` 0000000
- history: fix the unsaved history in the detached state `#D1795` 0000000
- edit: fix an unexpected leave from the command layout on `read` `#D1800` 0000000
- complete: do not attempt an independent rhs completion for arguments (reported by rsteube) `#D1787` f8bbe2c
- history: fix the unsaved history in the detached state `#D1795` 344168e
- edit: fix an unexpected leave from the command layout on `read` `#D1800` 4dbf16f

## Documentation

Expand Down Expand Up @@ -286,7 +286,7 @@
- complete: use `awk` for batch `quote-insert` (motivated by banoris) `#D1714` a0b2ad2 92d9734
- complete (quote-insert.batch): fix regex escaping in bracket expr of awk (reported by telometto) `#D1729` 8039b77
- prompt: reduce redundant evaluation of `PROMPT_COMMAND` on the startup `#D1778` 042376b
- main: run `ble/base/unload` directly at the end of `EXIT` handler `#D1797` 0000000
- main: run `ble/base/unload` directly at the end of `EXIT` handler `#D1797` 115baec

## Compatibility

Expand Down Expand Up @@ -341,6 +341,7 @@
- main, trap: fix initialization order of `{save,restore}-BASH_REMATCH` (reported by SuperSandro2000) `#D1780` 689534d
- global: work around bash-3.0 bug that single quotas remains for `"${v-$''}"` `#D1774` 9b96578
- util: work around old `vte` not supporting `DECSCUSR` yet setting `TERM=xterm` (reported by dongxi8) `#D1785` 70277d0
- progcomp: work around the cobra V2 description hack (reported by SuperSandro2000) `#D1803` XXXXXXX

## Internal changes and fixes

Expand Down
34 changes: 34 additions & 0 deletions lib/core-complete.sh
Expand Up @@ -3339,6 +3339,33 @@ function ble/complete/progcomp/.filter-and-split-compgen {
return 0
} 2>/dev/null

function ble/complete/progcomp/.cobraV2.patch {
local prefix=$cur
[[ $comps_flags == *v* ]] && prefix=$COMPV
local unprocessed has_desc=
unprocessed=()
local lines line cand desc
for lines in "${out[@]}"; do
ble/string#split-lines lines "$lines"
for line in "${lines[@]}"; do
if [[ $line == *$'\t'* ]]; then
cand=${line%%$'\t'*}
desc=${line#*$'\t'}
[[ $cand == "$prefix"* ]] || continue
ble/complete/cand/yield word "$cand" "$desc"
has_desc=1
else
ble/array#push unprocessed "$line"
fi
done
done
[[ $has_desc ]] && bleopt complete_menu_style=desc
if ((${#unprocessed[@]})); then
out=("${unprocessed[@]}")
ble/function#advice/do
fi
}

## @fn ble/complete/progcomp/.compgen opts
##
## @param[in] opts
Expand Down Expand Up @@ -3431,6 +3458,13 @@ function ble/complete/progcomp/.compgen {

ble/complete/mandb:_parse_help/inject
fi

# cobra GenBashCompletionV2
if [[ $comp_func == __start_* ]]; then
local target=__${comp_func#__start_}_handle_completion_types
ble/is-function "$target" &&
ble/function#advice around "$target" ble/complete/progcomp/.cobraV2.patch
fi
fi
if [[ $comp_prog ]]; then
# aws
Expand Down
29 changes: 29 additions & 0 deletions note.txt
Expand Up @@ -6193,6 +6193,35 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2022-04-05

* progcomp: cobra で生成される補完が説明を混入させる (reported by SuperSandro2000) [#D1803]
https://github.com/akinomyoga/ble.sh/issues/183

正直 cobra は bash-completion でも問題を起こしているし。元よりとても質が悪
いので余り対応したくないが、だからといって upstream に手を加えるのもまた対
応が遅くてどうしようもないという事が分かっている。不本意ながらこちらで
workaround を加える→取り敢えず対応した。一応動く。

改めて V2 の実装を確認したがやはり bash スクリプトとして質が悪い。

? そもそも説明を候補に含めるのは hack に過ぎないし、これに依存していると
bind 'set show-all-if-ambiguous' 等の時に正しく動作するのかも怪しい→と思っ
て確認してみたが一応大丈夫の様だ。

以前 bash-completion で make に対して起こったのは一体何だったのか。以下で
ある。

https://github.com/scop/bash-completion/issues/544
https://github.com/scop/bash-completion/pull/546

うーん。調べてみるとこの時とは条件が異なる。この時は COMP_TYPE が 9 or 37
の時には候補を勝手に変更しない様にしていた。これは挿入される候補の始まり
部分を省略できるかどうかの判定であり、少しでも挿入されたら困るので 9 も排
除している。42 は手落ちであろう。一方で今回は始まり部分は変えないので曖昧
の時には後ろに自由に勝手な文字列を追加する事ができる。という事により
37|42 の時にだけ気をつければ良い。

2022-03-19

* menu-complete: 補完候補に含まれる制御文字の反転は xor で行う [#D1802]
Expand Down

0 comments on commit 71d0736

Please sign in to comment.