简体   繁体   English

如何在bash中自动完成带空格的文件名?

[英]How can I get auto-completion in bash for file-names with spaces, too?

I'm pretty new to this whole Terminal business and had things working nicely on my old laptop with Snow Leopard installed. 我对整个终端业务都很陌生,并且在安装了Snow Leopard的旧笔记本电脑上运行良好。

New laptop with Snow Leopard works differently, however. 然而,Snow Leopard的新笔记本电脑工作方式不同。 When using the terminal, when trying to get auto-completion to work, it won't auto-complete for directory names with spaces in them. 使用终端时,尝试自动完成工作时,对于包含空格的目录名称,它不会自动完成。 I know I can type it in manually and escape that space, but I'd love to get auto-complete to work. 我知道我可以手动输入它并逃离那个空间,但我很乐意让自动完成工作。

What can I do here? 我能在这做什么?

You know, I'd swear this used to work and just seemed to stop working recently (last few months). 你知道,我发誓这曾经工作过,似乎最近停止工作(最近几个月)。 Don't know that any OS X updates updated bash, but whatever. 不知道任何操作系统X更新更新bash,但无论如何。

Anyway, putting "complete -o nospace -d cd" into .bashrc (or whatever rc file you're using) seems to give the desired behavior. 无论如何,将“完成-o nospace -d cd”放入.bashrc(或者你正在使用的任何rc文件)似乎给出了所需的行为。

Here is another solution which might be more straightforward. 这是另一种可能更直接的解决方案。 You have to the escape character \\ followed by a space 你必须使用转义字符 \\后跟一个空格

eg 例如

ls Xcode\ 5.0<tab>

Then "Xcode 5.0" would be considered as a whole string rather than two separate parameters. 然后“Xcode 5.0”将被视为整个字符串而不是两个单独的参数。

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

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