Bash 不会自动完成(Tab)文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22033261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash will not auto-complete (Tab) with files
提问by Finn
Auto-completion in bash (with Tab) works on folders, but notwith files.
bash 中的自动完成(使用 Tab)适用于文件夹,但不适用于文件。
- I'm running Ubuntu 13.10
- I haven't touched my .bashrcfile
- 我正在运行 Ubuntu 13.10
- 我没有碰过我的.bashrc文件
This is how the bottom part of the .bashrcfile looks, with the bash-completionpart installed and updated:
这是.bashrc文件底部的外观,安装并更新了bash-completion部分:
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
Any ideas?
有任何想法吗?
回答by that other guy
The third party "bash_completion" package (not to be confused with bash or its native completion) can sometimes be hard to predict.
第三方“bash_completion”包(不要与 bash 或其本机完成混淆)有时很难预测。
- Some commands are specifically set up to not never complete files, like
cd
- Some commands will refuse to complete certain filenames, because bash_completion doesn't realize the program handles them, like
mplayer
. - Some commands are just buggy, especially when paths contain spaces and other characters, like for
scp
.
- 某些命令专门设置为从不完成文件,例如
cd
- 有些命令会拒绝完成某些文件名,因为 bash_completion 没有意识到程序会处理它们,例如
mplayer
. - 有些命令只是有问题,特别是当路径包含空格和其他字符时,例如 for
scp
。
If you're ever in a situation where bash_completion isn't being helpful, you can use M-/
(aka Alt + /
) to use bash's native filename completion instead.
如果您遇到 bash_completion 没有帮助的情况,您可以使用M-/
(aka Alt + /
) 来代替使用 bash 的本机文件名完成。
If a command is frequently giving you trouble, you can disable bash_completion for this command using complete -r thatcommand
at the end of your .bashrc
.
如果某个命令经常给您带来麻烦,您可以在 .bashrccomplete -r thatcommand
的末尾使用此命令禁用 bash_completion .bashrc
。
回答by Troveldom
.bashrc file seems ok so the problem probably is in one of the bash_completion files.
.bashrc 文件似乎没问题,所以问题可能出在 bash_completion 文件之一中。
I suggest you backup the files and try to replace them with these:
我建议您备份文件并尝试用以下文件替换它们:
for /etc/bash_completion:
对于 /etc/bash_completion:
for /usr/share/bash-completion/bash_completion:
对于 /usr/share/bash-completion/bash_completion:
that are the standard completion files for ubuntu 13.10. Restart the console before checking if it worked.
这是 ubuntu 13.10 的标准完成文件。在检查它是否工作之前重新启动控制台。
回答by Chris Povirk
One possible cause for this is a file named !
. Some default bash-completion
setups have a bugwhen such a file exists. You can remove the file or patch /usr/share/bash-completion/bash_completion
as shown in the bug link.
造成这种情况的!
一个可能原因是名为. 当此类文件存在时,某些默认bash-completion
设置会出现错误。您可以删除/usr/share/bash-completion/bash_completion
错误链接中显示的文件或补丁。