我有一个存在于 ~/.unison/*.prf
中的一致配置文件列表。
我想要 bash 补全,这样当我键入 unison
或 unison-gtk
并点击 tab 时,它会列出 .prf
该文件夹中没有 .prf
部分的文件。
也许举个例子会更清楚:
$ ls ~/.unison/*.prf
default.prf dot-mozilla.prf to-desktop.prf
$ cd ~ # just to show you don't have to be in the ~/.unison folder
$ unison to<tab>
$ unison to-desktop
我预见到其他工具也需要这个,所以如果有可以重复使用的部件会很方便。
最佳答案
如果您正在运行 debian/ubuntu 或其他可能的 GNU/Linux 发行版,您的/etc/bash_completion.d/目录中应该有此类完成的示例。下面是一个示例,说明如何为齐奏设置完成脚本:
have unison &&
_unison_show()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($( compgen -W "$(for x in ~/.unison/*.prf; do echo $(basename ${x%.prf}); done)" -- $cur ) )
}
complete -F _unison_show unison
关于特殊目录中某些类型文件的 bash 补全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/803653/