Skip to content

Commit

Permalink
progcomp: disable "command_not_found_handle"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jul 8, 2022
1 parent 80f09c9 commit 64d471a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -362,6 +362,7 @@
- progcomp: work around the cobra V2 description hack (reported by SuperSandro2000) `#D1803` 71d0736
- complete: work around blocking `_scp_remote_files` and `_dnf` (reported by iantra) `#D1807` a4a779e 46f5c13
- history: work around broken timestamps in `HISTFILE` `#D1831` XXXXXXX
- progcomp: disable `command_not_found_handle` `#D1834` XXXXXXX

## Internal changes and fixes

Expand Down
7 changes: 6 additions & 1 deletion lib/core-complete.sh
Expand Up @@ -3115,7 +3115,7 @@ function ble/complete/progcomp/.compgen-helper-func {
local cmd=${COMP_WORDS[0]} cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
ble/function#push compopt 'ble/complete/progcomp/compopt "$@"'

# WA for blocking scp/ssh #D1807
# WA (#D1807): A workaround for blocking scp/ssh
ble/function#push ssh '
local IFS=$_ble_term_IFS
if [[ " ${FUNCNAME[*]} " == *" ble/complete/progcomp/.compgen "* ]]; then
Expand All @@ -3126,8 +3126,13 @@ function ble/complete/progcomp/.compgen-helper-func {
ble/function#push/call-top "$@"
fi'

# WA (#D1834): Suppress invocation of "command_not_found_handle" in the
# completion functions
ble/function#push command_not_found_handle

builtin eval '"$comp_func" "$cmd" "$cur" "$prev"' < /dev/null >&$_ble_util_fd_stdout 2>&$_ble_util_fd_stderr; local ret=$?

ble/function#pop command_not_found_handle
ble/function#pop ssh
ble/function#pop compopt

Expand Down
47 changes: 47 additions & 0 deletions note.txt
Expand Up @@ -6476,6 +6476,53 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2022-07-08

* complete: command_not_found_handle が自動補完で呼び出されて操作不能になる (reported by telometto, wisnoskij) [#D1834]
https://github.com/akinomyoga/ble.sh/issues/203
https://github.com/akinomyoga/ble.sh/issues/192

stdin に [y/n] を要求するが ble.sh が stdin をブロックしている為に補完が終
了できず操作不能になる。

? というか入力が受け付けられなくなったとしても C-c だけは効く様にして良いの
ではないか。

x 一方で、C-c をそのまま有効にすると ble.sh の処理自体がその場で止まって
しまう事になる。C-c を trap で捕まえて適切な stack frame まで戻るにして
も再び DEBUG トラップで複雑な事をしなければならない。

x そもそも外部コマンドの C-c を正しく検出できるのかという問題もある。C-c
で外部コマンドだけが終了したとして、その後補完スクリプトがそのまま走っ
た時に変な事にならないかというのは非自明である。

x 更に補完の度に stty を呼び出して C-c の状態を変えなければならない。失敗
すると次に stty を調整する迄 C-c を ble.sh で受信できなくなる。

うーん。色々考えると C-c を一時的に有効にするというのも余り良い選択肢では
ない様に思われる。取り敢えずは command_not_found_handle を一時的に無効に
するしかない。

* bash-completion の側でも修正するべきか。もし plain Bash では progcomp の
最中には command_not_found_handle が無効化されるという事であれば
bash-completion の側で修正は必要にはならない。

command_not_found_handle() { echo "$FUNCNAME is called"; }


既に bash-completion で報告されていないか確認する。

https://github.com/scop/bash-completion/pull/390

ここで既に議論されている。scop は upstream bash に request できないかとい
う事を提案している。他にも色々の箇所でそういうのがあるとも述べている。

と言っても将来的に Bash の側で off にする機能ができるとしても、古い Bash
は依然として存在するので取り敢えず個別に対応していくべきなのではないかと
いう気がする。

取り敢えず command_not_found_handle は function#push する事にする。

2022-07-07

* main: fd 0, 1 が TTY かどうかのチェックが常に偽になっている [#D1833]
Expand Down

0 comments on commit 64d471a

Please sign in to comment.