feat: support _comp_complete_minimal completion #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix ./foo completion
Bash 在沒有針對某個命令載入任何 completion spec 時,會走 _comp_complete_minimal,它只做 _comp_initialize 後直接 compopt -o bashdefault -o default,不會呼叫 _comp_compgen__call_builtin,hook 的 _comp_compgen__call_builtin 根本沒機會執行。
解決方案
自訂覆写 _comp_complete_minimal()
如果 COMP_WORDS[0] 有 /,就主動執行 _comp_initialize -- "$@",然後呼叫 _filedir。這一步會產生和原本檔案補全一樣的候選清單,因此會觸發(或重用) _comp_compgen__call_builtin,進而讓我們後面注入拼音匹配 _add_completion。
若不是路徑型命令,就回退到原本的 __bak_comp_complete_minimal,保持預設行為。
FIX scp completion
bash-completion 會通過 _comp_compgen__call_builtin 或 _comp_xfunc 兩層流程產生候選項。
原本只在 _comp_compgen__call_builtin 做補全
但 scp、sftp 這類指令會讓 comp_xfunc 執行它們自己的 compgen_local* 產生器,完全繞過那層,於是需要額外的 hook。
解決方案
在 _comp_xfunc 完成原本工作後,檢查被呼叫的產生器名稱。若符合規則,就把該次補全加入拼音補全邏輯。
因此只要某個補全從 _comp_xfunc 回傳本地路徑,就會自動得到拼音結果,無需逐一對命令打補丁。