bash 补全可防止退格键
我正在尝试为我编写的实用程序脚本设置 bash 完成,因此我将以下脚本添加到 /etc/bash_completion.d:
_mcd()
{
local cur words
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
words=`mcd-completion-words`
COMPREPLY=( $(compgen -W "${words}" -- "$cur") )
return 0
}
complete -F _mcd mcd
mcd-completion-words
脚本以编程方式查找命令的可用运算符。当我重新启动 bash(或获取脚本)时,我可以成功使用 Tab 键完成,但如果这样做,我将无法再退格到已完成的字符之后。
另外,如果我尝试列出所有选项(例如,我尝试用制表符完成,但没有任何单词),bash 会在命令中添加一个制表符,而我也无法退格。
如何让 bash 模仿正常的文件完成行为?任何帮助表示赞赏。谢谢!
这是 mcd-completion-words 的简化测试用例,但仍然表现出相同的行为。奇怪的是,丹尼斯的案例也适用于我(例如,当替换为“一二三”时)。
#!/usr/bin/env php
<?php
print "one two three four five six seven eight nine";
I am trying to set up bash completion for a utility script I wrote, so I added the following script to /etc/bash_completion.d:
_mcd()
{
local cur words
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
words=`mcd-completion-words`
COMPREPLY=( $(compgen -W "${words}" -- "$cur") )
return 0
}
complete -F _mcd mcd
The mcd-completion-words
script programmatically finds available operators for the command. When I restart bash (or source the script), I can successfully tab complete, but if I do so, I can no longer backspace past a completed character.
Also, if I attempt to list all options (e.g. I attempt to tab complete w/ no word in place), bash adds a tab to the command, which I also cannot backspace.
How can I make bash mimic normal file completion behavior? Any help is appreciated. Thanks!
Here's a reduced testcase for mcd-completion-words that still exhibits the same behavior. Curiously, Dennis' case works for me as well (when substituting in words="one two three", for example).
#!/usr/bin/env php
<?php
print "one two three four five six seven eight nine";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个简化的测试用例;即使是空的“php”命令也会导致错误的完成行为:
这是在带有 bash-3.2.48/bash-4.0.33 和 bash-3.2.48/bash-4.0.33 的机器(Ubuntu)上。 php-5.2.6-3ubuntu4。在另一台机器(Debian)上有 bash-3.2.39 & php-5.2.6-1+lenny9,完成&退格键一切正常。
使用
perl -e ""
而不是php -r ""
也可以。不知道怎么回事,php与readline冲突?也许你可以尝试 bug-bash 邮件列表?
Here's a reduced test case; even an empty `php' command causes the erroneous completion behaviour:
This is on machine (Ubuntu) with both bash-3.2.48/bash-4.0.33 & php-5.2.6-3ubuntu4. On another machine (Debian) with bash-3.2.39 & php-5.2.6-1+lenny9, completion & backspace goes all right.
Using
perl -e ""
instead ofphp -r ""
also goes all right.Don't know what's going on, php conflicting with readline? Maybe you can try bug-bash mailing list?