我想创建一个 bash 完成脚本,它识别表单--arg
和--some-arg=file
.
阅读本教程和 中的一些示例后/usr/share/bash_completion/completions/
,我编写了以下脚本(以节省使用 Chromium 键入一些标志的时间):
_chromium()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Some interesting options
opts="
--disable-web-security
--easy-off-store-extension-install
--incognito
--load-extension=
--pack-extension=
--pack-extension-key=
--user-data-dir=
"
# Handle --xxxxxx=file
if [[ ${cur} == "--"*"=" ]] ; then
# Removed failures (is my logic OK?)
return 0
fi
# Handle other options
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi …
Run Code Online (Sandbox Code Playgroud)