简体   繁体   English

如何使bash tab-completion像windows'cmd.exe一样工作?

[英]How to make bash tab-completion work like windows' cmd.exe?

Say I have a folder with files in it with names like this: 假设我有一个包含文件的文件夹,其名称如下:

  • log_1.log
  • log_2.log
  • log_2.gz

And I want to perform some operation, let's say move, on log_2.gz. 我想在log_2.gz上执行一些操作,比如说移动。

In Windows cmd.exe, I am used to performing these steps: 在Windows cmd.exe中,我习惯于执行以下步骤:

  1. Type move (and nothing else) 键入move (没有别的)
  2. tab tab tab to traverse the tab-complete options until I get to log_2.gz 选项 选项 选项 遍历选项卡完成选项,直到我到达log_2.gz
  3. Type destination 输入destination

But in bash shell (within iTerm2 on Mac OS X 10.8.3), I have to do something like this: 但是在bash shell中(在Mac OS X 10.8.3上的iTerm2中),我必须做这样的事情:

  1. Type mv l 输入mv l
  2. tab which takes me to log_ and makes an annoying beep sound 标签 ,它带我log_并发出恼人的哔哔声
  3. Type 2 类型2
  4. tab which takes me to log_2. 标签这需要我log_2. and makes an annoying beep sound 并发出恼人的哔哔声
  5. Type g 输入g
  6. tab which takes me to log_2.gz and is satisfyingly silent 选项 log_2.gz我到log_2.gz并且令人满意地保持沉默
  7. Type destination 输入destination

As you can see, bash requires many more steps even when you know the destination filename, but imagine a scenario where you are not really certain what exactly is in the filename (maybe the ls was too long). 正如您所看到的,即使您知道目标文件名,bash也需要更多步骤,但想象一下您不确定文件名究竟是什么的场景(可能是ls太长)。 I often find myself in this scenario after a few tab + typing and am forced to abandon the command, run ls again, copy the filename, maybe even run a pwd to concatenate with the folder, and then resume where I left off. 我经常发现自己在这个场景中经过一些标签 +打字并被迫放弃命令,再次运行ls ,复制文件名,甚至可以运行pwd与文件夹连接,然后从我离开的地方继续。 This is very annoying. 这非常烦人。

You can add the following in your .inputrc (if you don't have one, then create it) file. 您可以在.inputrc添加以下内容(如果您没有,则创建它)文件。 Once added, either source the file or logout and log back in. 添加后,请获取文件或注销并重新登录。

set show-all-if-ambiguous on
set completion-ignore-case on
TAB: menu-complete

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

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