【发布时间】:2020-08-03 16:12:27
【问题描述】:
我为我的脚本创建了一个漂亮的自动完成功能。
但有一件事:当参数留给用户决定时(例如,第一个参数是新项目的名称),我想显示一行描述预期的内容。
For example:
$> script [TAB][TAB]
<name of project>
$> script my_new_project
.
当然,我想过这个:
if [ $COMP_CWORD -eq 1 ]; then
local IFS=$'\n'
COMPREPLY+=($(compgen -W "<name of project>"))
问题是我得到了这个:
$> script [TAB][TAB]
$> script <name of project>
也就是说,当我按 TAB 时,我定义的一个文本会自动添加到命令行中。
.
我也试过这个:
local IFS=$':'
COMPREPLY+=($(compgen -W "Help: <domain name associated with the project>"))
但是结果是乱码,还是在命令行中加了字:
$> script [TAB][TAB]
<domain name associated with the project> Help:
$> script <domain name associated with the project>
.
请问,您知道如果有一种heredoc 用于自动完成,它只会显示帮助文本,但不会添加到命令行?
谢谢!
【问题讨论】:
-
您可能会发现this approach 很有用。我还没试过。但我也需要你要求的同样效果。
-
哇,有时需要耐心^^谢谢您的评论,我会尽快看看
-
我已经用 heredoc 示例更新了答案。
标签: bash autocomplete completion