中间命令 alias/function

Mid-command alias/function

因为我经常使用&& !!,所以我想知道有没有办法缩短它(现在我需要为此移动很多)。 示例用例:

$ alias ¤¤='\&\& \!\!' # This is not a mid-command alias
$ echo a
a
$ echo b ¤¤
b
a

bash 没有等同于 zsh 全局别名(可以在命令中的任何地方扩展,如您所愿)。 Readline 宏可能更合适:

$ bind '"¤¤": "&& !!"'
$ echo a
$ echo b ¤¤
b
a

请注意,当您键入 ¤¤ 时,Readline 会立即将这两个字符替换为 && !!(此处很难演示)。

要确保它在您的 shell 中始终可用,请添加

bind '"¤¤": "&& !!"'

到您的 .bashrc 文件,或添加

$if Bash
"¤¤": "&& !!"
$endif

到您的 .inputrc 文件。 (请注意 .inputrcbash 以外的程序读取,并且这个特定的宏可能不值得为其他程序定义。)