为自定义命令前面的所有命令保留 Bash Completion
我有一个允许在后台执行 Bash 进程的脚本,我称之为“backy”。我想在后台运行的程序是这样调用的:
backy long-running-script param1 param2
现在的问题是,如果我在前面添加另一个脚本,我会失去 long-running-script
的 Bash 补全。
我想编写一个 Bash 完成文件,它不仅保留 long-running-script
的 Bash 完成及其所有参数,还保留我想用 backy 调用的每个其他脚本。
我对 Bash 完成有一些经验,但我只是缺少可以插入到 Bash 完成脚本中的命令,以便它随着要调用的脚本的完成而完成。有什么想法吗?
到目前为止我的完成情况:
have backy &&
_backy_complete()
{
local cur prev goals
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# How to get the completion from the script that is the param for backy,
# in a generic way?
COMPREPLY=( ????? )
return 0
} &&
complete -F _backy_complete backy
编辑 - 解决方案:
感谢 Lekensteyn,我用这一行替换了现有 bash 完成脚本的内容:
complete -F _command backy
I have a script which allows to execute Bash processes in the background, i called it "backy". Programs I want to run in background I call like this:
backy long-running-script param1 param2
The problem is now that I loose the Bash completion for long-running-script
if I prepend another script.
I want to write a Bash completion file which preserves not only the Bash completion for long-running-script
and all of its parameters, also for every other script that I want to call with backy.
I have some experience with Bash completion, but I'm just missing the command which I can insert into my Bash completion script so that it completes with the completion of the script that is to be called. Any ideas?
My completion so far:
have backy &&
_backy_complete()
{
local cur prev goals
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# How to get the completion from the script that is the param for backy,
# in a generic way?
COMPREPLY=( ????? )
return 0
} &&
complete -F _backy_complete backy
EDIT - SOLUTION:
Thanks to Lekensteyn, I replaced the content of my existing bash completion script with just this line:
complete -F _command backy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于这种情况已经有一个 bash_completion 函数:
它用于自动完成 sudo、fakeroot 等之后的命令。传递给 backy 的任何参数都会被忽略,例如:
There is already a bash_completion function for such cases:
It's used for autocompleting the commands after
sudo
,fakeroot
and others. Any arguments passed to backy are ignored like: