我已經為:命令撰寫了以下示例完成(以了解完成失敗的原因):
__sample_complete()
{
local OPTIONS=('--first' '--first=')
local FIRST_ARGUMENTS=('arg1' 'arg2')
local current=$2
local previous=$3
case $current in
--first=*)
current=${current##--first*,}
readarray -t COMPREPLY < <(compgen -o nospace -W "${FIRST_ARGUMENTS[*]}" -- "$current")
;;
*)
readarray -t COMPREPLY < <(compgen -W "${OPTIONS[*]}" -- "$current")
;;
esac
}
complete -F __sample_complete :
我想arg1 arg2在我輸入時看到建議,: --first=但現在 Bash 會自動在 Tab 按下時用--first:完成它--first=--first。
uj5u.com熱心網友回復:
該詞--first=在 COMP_WORDBREAKS 上拆分,因此--first被視為另一個詞。除錯真的很簡單——添加args=("$@"); declare -p args到你的腳本中并檢查引數——當前詞是空的,前一個詞是--first.
case "$3" in
--first) compgen -o nospace -W "${FIRST_ARGUMENTS[*]}" -- "$2"
我總是使用 COMP* 變數,不知道哪個更好。我喜歡https://devmanual.gentoo.org/tasks-reference/completion/index.html。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/362987.html
標籤:猛击
