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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:42:18  来源:igfitidea点击:

Bash will not auto-complete (Tab) with files

linuxbashubuntuterminalbash-completion

提问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 或其本机完成混淆)有时很难预测。

  1. Some commands are specifically set up to not never complete files, like cd
  2. Some commands will refuse to complete certain filenames, because bash_completion doesn't realize the program handles them, like mplayer.
  3. Some commands are just buggy, especially when paths contain spaces and other characters, like for scp.
  1. 某些命令专门设置为从不完成文件,例如 cd
  2. 有些命令会拒绝完成某些文件名,因为 bash_completion 没有意识到程序会处理它们,例如mplayer.
  3. 有些命令只是有问题,特别是当路径包含空格和其他字符时,例如 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 thatcommandat 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:

http://pastebin.com/0HWHsbyR

http://pastebin.com/0HWHsbyR

for /usr/share/bash-completion/bash_completion:

对于 /usr/share/bash-completion/bash_completion:

http://pastebin.com/c49KrbXT

http://pastebin.com/c49KrbXT

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-completionsetups have a bugwhen such a file exists. You can remove the file or patch /usr/share/bash-completion/bash_completionas shown in the bug link.

造成这种情况!一个可能原因是名为. 当此类文件存在时,某些默认bash-completion设置会出现错误。您可以删除/usr/share/bash-completion/bash_completion错误链接中显示的文件或补丁。