コマンドのbash補完を実行しようとしていますが、フルワードコマンドではすべてが正常に機能していますが、「-」フラグを補完しようとすると、次のコード(後にcomplete -F _keybase keybase
)を使用して、 2つのタック(つまりkeybase --h<TAB>
)compgenの使用エラーが発生します。(keybase --<TAB>
ただし、期待どおりに機能します)。これはUbuntu18.04にあります。このファイルは、ログオンスクリプトの一部としてではなく、現在のシェルセッションで調達しています(まだ)。
_keybase() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
#...code removed for brevity
if [[ ${cur} == -* ]]; then
# complete the "--" parameters
opts=$(keybase help advanced | grep -Po '\-\-[a-z\-]+' | tr "\n" " ")
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
fi
}
これは私がタイプしたときに印刷されるものです keybase --h<TAB>
keybase --hbash: compgen: --: invalid option
compgen: usage: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]
引用符のエスケープを微調整し、$ optの定義で改行を追加/削除し、compgenの2番目の引数として「-」を追加/削除しました(Debianの記事の説明のbash完了 keybase help advanced | grep -Po '\-\-[a-z\-]+' | tr "\n" " "
出力の要請でこれらを追加しました:
--api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version
そして、compgenが実行されると予想されるコマンドをエコーすると、期待するコマンドが取得されecho "compgen -W \"${opts}\" -- ${cur}"
、実際にターミナルで正常に実行されるコマンドが表示されます。
compgen -W "--api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version " -- --h
--home
--help
コードはFedora29で動作することが判明し、これはUbuntuのバグであり、スクリプトのバグではないと私は信じています。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加