为自定义命令前面的所有命令保留 Bash Completion

发布于 2024-11-02 10:53:49 字数 859 浏览 0 评论 0原文

我有一个允许在后台执行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧话新听 2024-11-09 10:53:49

对于这种情况已经有一个 bash_completion 函数:

complete -F _command backy

它用于自动完成 sudo、fakeroot 等之后的命令。传递给 backy 的任何参数都会被忽略,例如:

backy --whatever --this --is=ignored not ignored anymore

There is already a bash_completion function for such cases:

complete -F _command backy

It's used for autocompleting the commands after sudo, fakeroot and others. Any arguments passed to backy are ignored like:

backy --whatever --this --is=ignored not ignored anymore
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文