使用compgen获得自动完成另一个命令,要使用的标志? [英] Use compgen to get autocomplete for another command, which flag to use?
问题描述
我有一个自定义自动完成指令(称之为 commandA
)
I have a custom auto-completed command (call it commandA
)
在 commandB
我要偷自动完成选项的第一个参数commandA
in commandB
I want to steal the autocomplete options for the first argument to commandA
因此,例如,用于参数1的commandA选项是:
So, for example the options for argument1 for commandA are:
ABCDEF
ABCABC
ABC123
我想沿着东西线 compgen - ? commandA
或 compgen - ? commandA ABC
来产生上面的列表中。
I would like something along the lines of
compgen -? "commandA"
or compgen -? "commandA abc"
to generate the list above.
推荐答案
您可以使用完整-p commandA
来找出哪个函数将被调用来进行自定义为完成该命令。 (你需要寻找的参数-F选项。如果有其他optiond,它变得更加复杂。)
You can use complete -p commandA
to find out which function would be invoked to do custom completion for that command. (You need to look for the argument to the -F option. If there are other optiond, it becomes more complicated.)
您会再需要设置标准完成环境变量(他们的名字开始COMP_),并调用具有appropiate论据功能。这将填补COM prePLY变量;如果需要的话,可以再添加其他的可能性。请参阅 bash的手动获得详细信息。
You would then need to set up the standard completion environment variables (whose names start COMP_) and call that function with appropiate arguments. It will fill in the COMPREPLY variable; if necessary, you could then add other possibilities. See the bash manual for details.
这篇关于使用compgen获得自动完成另一个命令,要使用的标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!