From 9d4ad569430166535f4ef18c99e23443a52813be Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Thu, 6 May 2021 16:40:13 +0900 Subject: [PATCH] complete: work around bash-completion bugs --- lib/core-complete.sh | 15 +++++++++++++++ memo/ChangeLog.md | 1 + note.txt | 17 ++++++++++++++++- src/util.sh | 8 +++++--- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/core-complete.sh b/lib/core-complete.sh index 27da455b..318aa4b9 100644 --- a/lib/core-complete.sh +++ b/lib/core-complete.sh @@ -2385,8 +2385,23 @@ function ble/complete/progcomp/.compgen { ble/array#push compoptions "-$c" "$o" ;; (F) comp_func=${compargs[iarg++]} + + # Workarounds for third-party plugins [[ $comp_func == _fzf_* ]] && ble-import contrib/fzf-completion + if ble/is-function _quote_readline_by_ref; then + # Fix bash_completion + function _quote_readline_by_ref { + if [[ $1 == \'* ]]; then + printf -v "$2" %s "${1:1}" + else + printf -v "$2" %q "$1" + [[ ${!2} == \$* ]] && eval $2=${!2} + fi + } + ble/function#suppress-stderr _filedir + fi + ble/array#push compoptions "-$c" ble/complete/progcomp/.compgen-helper-func ;; (C) comp_prog=${compargs[iarg++]} diff --git a/memo/ChangeLog.md b/memo/ChangeLog.md index 70f6e892..6b2cced7 100644 --- a/memo/ChangeLog.md +++ b/memo/ChangeLog.md @@ -84,6 +84,7 @@ - syntax: fix a bug that `eval() { :; }`, `declare() { :; }` are not treated as function definition `#D1529` 0000000 - decode: fix a hang on attach failure by cache corruption `#D1531` 0000000 - edit, etc: add workarounds for `localvar_inherit` `#D1532` 0000000 +- complete: work around bash-completion bugs `#D1533` 0000000 ## Compatibility diff --git a/note.txt b/note.txt index d4460561..34a113ff 100644 --- a/note.txt +++ b/note.txt @@ -1255,11 +1255,17 @@ bash_tips ******************************************************************************* - bug-bash + bug-bash, third-party bugs ------------------------------------------------------------------------------- 2021-05-06 + * bash-completion + https://github.com/akinomyoga/ble.sh/issues/97 + Ref #D1533 + + python のテストを自分で実装したりしなければならず面倒である。 + * bug-bash localvar_inherit: dynamic variables の性質も継承されるのは意図的か。 Ref #D1532 @@ -4343,6 +4349,15 @@ bash_tips 2021-05-06 + * complete: bash-completion bug workarounds (reported by oc1024) [#D1533] + https://github.com/akinomyoga/ble.sh/issues/97 + + 自分の手許でも色々エラーメッセージが出てうるさい。 + + bash-completion で修正を掛けるのは面倒だし時間がかかりそう。更に、各種 + distribution に波及する迄に更に時間もかかりそうなので取り敢えず暫定的に、 + ble.sh の側で bash-completion の実装を上書きする事にしてしまう。 + * 2021-04-06 localvar_inherit で動かなくなっている [#D1532] 或いは元から動いた事はなかった可能性も? diff --git a/src/util.sh b/src/util.sh index 1f0cf937..58546748 100644 --- a/src/util.sh +++ b/src/util.sh @@ -2497,11 +2497,13 @@ function ble/function#suppress-stderr { return 2 fi - local def; ble/function#getdef "$name" - builtin eval "ble/function#suppress-stderr:$def" + # 重複して suppress-stderr した時の為、未定義の時のみ実装を待避 local lambda=ble/function#suppress-stderr:$name + if ! ble/is-function "$lambda"; then + local def; ble/function#getdef "$name" + builtin eval "ble/function#suppress-stderr:$def" + fi - local q=\' Q="'\''" builtin eval "function $name { $lambda \"\$@\" 2>/dev/null; }" return 0 }