简体   繁体   English

Bash不会自动完成(Tab)文件

[英]Bash will not auto-complete (Tab) with files

Auto-completion in bash (with Tab) works on folders, but not with files. bash中的自动完成(使用Tab)适用于文件夹,但不适用于文件。

  • I'm running Ubuntu 13.10 我正在运行Ubuntu 13.10
  • I haven't touched my .bashrc file 我没有触及我的.bashrc文件

This is how the bottom part of the .bashrc file looks, with the bash-completion part 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? 有任何想法吗?

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 某些命令专门设置为永远不会完成文件,如cd
  2. Some commands will refuse to complete certain filenames, because bash_completion doesn't realize the program handles them, like mplayer . 有些命令会拒绝完成某些文件名,因为bash_completion没有意识到程序会处理它们,就像mplayer一样。
  3. Some commands are just buggy, especially when paths contain spaces and other characters, like for scp . 有些命令只是错误,特别是当路径包含空格和其他字符时,例如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 . 如果命令经常给您带来麻烦,您可以使用.bashrc末尾的complete -r thatcommand命令禁用此命令的complete -r thatcommand

.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: for / etc / bash_completion:

http://pastebin.com/0HWHsbyR http://pastebin.com/0HWHsbyR

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

http://pastebin.com/c49KrbXT http://pastebin.com/c49KrbXT

that are the standard completion files for ubuntu 13.10. 这是ubuntu 13.10的标准完成文件。 Restart the console before checking if it worked. 在检查它是否有效之前重新启动控制台。

One possible cause for this is a file named ! 一个可能的原因是一个名为!的文件! . Some default bash-completion setups have a bug when such a file exists. 当存在这样的文件时,某些默认的bash-completion设置会出现错误 You can remove the file or patch /usr/share/bash-completion/bash_completion as shown in the bug link. 您可以删除文件或补丁/usr/share/bash-completion/bash_completion ,如错误链接中所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM