我想尽可能少地修改文件,所以.inputrc除非万不得已,否则我不想碰。因此,给定的.inputrc行如下:
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Run Code Online (Sandbox Code Playgroud)
我怎样才能只使用它们来应用它们bash?
这个 SU 帖子表明bind可以从.inputrc和bind的帮助中读取:
$ help bind
bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
Run Code Online (Sandbox Code Playgroud)
history-search-* 看起来像 readline 函数,所以我试过:
bind "\e[6~":history-search-forward
bind "\e[5~":history-search-backward
Run Code Online (Sandbox Code Playgroud)
Page Up现在触发铃声,Page Down打印一个~.
有没有一种通用的方法可以让我在 中使用inputrc行bash?
对于其他搜索的人来说,这适用于所有 inputrc命令:只需将它们用引号括起来,bind在前面推一个,就可以了(如果实际inputrc命令本身需要引号,请确保有不同类型的引号)。
例如,一个inputrc可以有
# makes tab-completion *immediately* return multiple options,
set show-all-if-ambiguous on
# bind C-d to go forword, not crush the shell
"\C-d": shell-forward-word
Run Code Online (Sandbox Code Playgroud)
要将它们放入您的中bashrc,只需
bind "set show-all-if-ambiguous on"
bind '"\C-d": shell-forward-word'
Run Code Online (Sandbox Code Playgroud)
根据我所拥有的,.bashrc你需要类似的东西
bind '"\e[6~": history-search-forward'
Run Code Online (Sandbox Code Playgroud)