题
我有一个unison配置文件列表,它存在于〜/ .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/目录中应该有这种类型的完成示例。以下是如何为unison设置完成脚本的示例:
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
不隶属于 StackOverflow