Bash 选项卡完成在第一次完成后会增加额外的空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11981764/
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 03:03:10  来源:igfitidea点击:

Bash tab completion adds extra space after the first completion

bashtab-completion

提问by shiquanwang

Bash tab completion adds extra space after the first completion which stops further completion if the compeletion target is a file in multi-level folders.

Bash 选项卡完成会在第一次完成后增加额外的空间,如果完成目标是多级文件夹中的文件,则会停止进一步的完成。

For example, I have a file in the path ~/Documents/foo/bar.txt, and I want to list it. I face the following problem, when input

例如,我在路径 ~/Documents/foo/bar.txt 中有一个文件,我想列出它。我面临以下问题,当输入

a@b:~$ls Docu <TAB>

I get

我得到

a@b:~$ls Documents |(<-this is the cursor, so there is an extra space afer Documents)

So I cannot further tab complete. I have to backspace to delete the extra space.

所以我无法进一步完成标签。我必须退格才能删除多余的空间。

Normally I want to get:

通常我想得到:

a@b:~$ls Docu <TAB>
a@b:~$ls Documents/ <TAB>
a@b:~$ls Documents/foo/ <TAB>
a@b:~$ls Documents/foo/bar.txt

回答by tlo

Just for the record: There is also a bug in the adobereader-enu (acroread) package that breaks bash completion. In this case you can just delete the symlink:

只是为了记录:adobereader-enu (acroread) 包中还有一个错误会破坏 bash 完成。在这种情况下,您可以删除符号链接:

rm /etc/bash_completion.d/acroread.sh

See also: https://bugs.launchpad.net/ubuntu/+source/acroread/+bug/769866

另见:https: //bugs.launchpad.net/ubuntu/+source/acroread/+bug/769866

回答by John

I have had this same problem with my bash completion in both Ubuntu 11.10 and 12.04. I found that I was able to get many commands to start working correctly by editing /etc/bash_completion. Specifically, I commented out the following section:

我在 Ubuntu 11.10 和 12.04 中完成 bash 时遇到了同样的问题。我发现我可以通过编辑 /etc/bash_completion.conf 来获得许多命令以开始正常工作。具体来说,我注释掉了以下部分:

####
# makeinfo and texi2dvi are defined elsewhere.
#
#for i in a2ps awk bash bc bison cat colordiff cp csplit \
#    curl cut date df diff dir du enscript env expand fmt fold gperf gprof \
#    grep grub head indent irb ld ldd less ln ls m4 md5sum mkdir mkfifo mknod \
#    mv netstat nl nm objcopy objdump od paste patch pr ptx readelf rm rmdir \
#    sed seq sha{,1,224,256,384,512}sum shar sort split strip tac tail tee \
#    texindex touch tr uname unexpand uniq units vdir wc wget who; do
#    have $i && complete -F _longopt -o default $i
#done

Now ls works well again. I have not figured out yet why mv is still mis-behaving.

现在 ls 再次运行良好。我还没有弄清楚为什么 mv 仍然表现不佳。

回答by Tarun

This has been answered hereat askubuntu. It is related to the bug here

这已经回答了这里的askubuntu。它与此处的错误有关

Relevant answer from the above thread:

来自上述线程的相关答案:

edit /etc/bash_completion line 1587, change default to filenames (make a backup first).

编辑 /etc/bash_completion 第 1587 行,将默认值更改为文件名(先备份)。

回答by Mike

i also got around the problem by changing _filedir with _filedir_pdf in /etc/bash_completion.d/acroread.sh (Ubuntu 12.04)

我还通过在 /etc/bash_completion.d/acroread.sh (Ubuntu 12.04) 中用 _filedir_pdf 更改 _filedir 来解决这个问题

acroread bash completion changes the _filedir function thereby altering the behaviour of a lot of other alsobash completion functions

acroread bash 完成更改了 _filedir 函数,从而改变了许多其他 alsobash 完成函数的行为