如何在bash中内联扩展通配符?


10

我记得bash可以执行以下操作:

假设当我输入以下内容时,当前目录中有3个文件:a,b,c:

$> somecommand *

然后按一个键或多个组合键或一个键序列,通配符*在线将展开为:

$> somecommand a b c

但我不记得,也无法用谷歌搜索出密钥顺序!帮帮我!


5
尝试Ctrl-X *
斯特凡Chazelas

Answers:


7

如果不是,则需要绑定glob-expand-word到键序列。通常通过添加以下内容:

"\C-x*": glob-expand-word

.inputrc

要检查当前状态,请执行以下操作:

bind -P | grep glob-expand-word

结果可能是:

glob-expand-word can be found on "\C-x*".

这意味着:

Ctrl-x*

这也很有可能起作用:

Ctrl-xCtrl-*


看看bind -P其他手册和手册。


3

看来您正在寻找清单完成。在手册页中bash

 COMP_TYPE
     Set to an integer value corresponding to the type of completion
     attempted  that caused a completion function to be called: TAB,
     for normal completion, ?, for listing completions after succes
     sive  tabs, !, for listing alternatives on partial word comple
     tion, @, to list completions if the word is not unmodified,  or
     %,  for  menu  completion.   This variable is available only in
     shell functions and external commands invoked by  the  program
     mable completion facilities

因此,这取决于完成命令的完成功能。


2

如果您set -o vi在bash 中使用,则Ctrl-X*无法使用。

set -o vi模式下,您需要使用Esc*


1
值得一提的是,一旦您进入正常模式,<C-X>*就可以使用,但是它<C-X>是多余的,什么也不做。(<C-X>不会像vi中那样递减。)如果处于插入模式,则必须先使用<Esc>
wchargin 2015年

这很棒。这些叫什么?bash键盘快捷键?有一些文档可以在其中找到更多这些键盘快捷键吗?
wisbucky

2
@wisbucky:有点晚了,但是对于其他人,GNU Readline负责这些。当您遇到困难时,请阅读的“编辑命令”部分man readline。我使用Bash已有10年了,但我仍在学习新的东西。
Soren Bjornstad '19
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.